List of usage examples for org.openqa.selenium WebDriver findElement
@Override WebElement findElement(By by);
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs//from w w w . j av a 2s . c o m */ @Test @Alerts(DEFAULT = "page2.html", IE = "") public void clickNestedInputImageElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='image' id='theInput' />\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement input = driver.findElement(By.id("theInput")); assertEquals("input", input.getTagName()); input.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs/* www . j a v a 2s . c o m*/ */ @Test @Alerts(DEFAULT = "page2.html", IE = "") public void clickNestedInputTextElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='text' id='theInput' />\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement input = driver.findElement(By.id("theInput")); assertEquals("input", input.getTagName()); input.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs/*w ww . j a v a2s . co m*/ */ @Test @Alerts(DEFAULT = "page2.html", IE = "") public void clickNestedInputPasswordElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='password' id='theInput' />\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement input = driver.findElement(By.id("theInput")); assertEquals("input", input.getTagName()); input.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs/*from w w w .j av a2 s . co m*/ */ @Test public void clickNestedOptionElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <select>\n" + " <option id='theOption'>test</option>\n" + " </select>\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement option = driver.findElement(By.id("theOption")); assertEquals("option", option.getTagName()); option.click(); assertEquals(URL_FIRST + "page2.html", driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs//from w ww . j ava 2s .c o m */ @Test @Alerts(DEFAULT = "", FF = "page2.html") public void clickNestedRadioElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='radio' id='theRadio' name='myRadio' value='Milk'>\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement radio = driver.findElement(By.id("theRadio")); assertEquals("input", radio.getTagName()); radio.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs/*from www . j a v a 2 s . co m*/ */ @Test @Alerts("page2.html") public void clickNestedResetElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='reset' id='theInput' />\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement input = driver.findElement(By.id("theInput")); assertEquals("input", input.getTagName()); input.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if an error occurs// www . j ava 2s.c o m */ @Test @Alerts("page2.html") public void clickNestedSubmitElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='submit' id='theInput' />\n" + " </a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); final WebElement input = driver.findElement(By.id("theInput")); assertEquals("input", input.getTagName()); input.click(); assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if the test fails//from ww w. j a v a 2 s . c om */ @Test @Alerts({ "", "#anchor", "#!bang" }) public void dontReloadHashBang() throws Exception { final String html = "<html>\n" + "<head><title>foo</title></head>\n" + "<body>\n" + " <a href='" + URL_FIRST + "test' id='a1'>link1</a>\n" + " <a href='" + URL_FIRST + "test#anchor' id='a2'>link2</a>\n" + " <a href='" + URL_FIRST + "test#!bang' id='a3'>link3</a>\n" + " <script>\n" + " alert(document.getElementById('a1').hash);\n" + " alert(document.getElementById('a2').hash);\n" + " alert(document.getElementById('a3').hash);\n" + " </script>\n" + "</body></html>"; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setDefaultResponse(html); final WebDriver driver = loadPageWithAlerts2(html); assertEquals(1, webConnection.getRequestCount()); driver.findElement(By.id("a1")).click(); assertEquals(2, webConnection.getRequestCount()); verifyAlerts(driver, getExpectedAlerts()); driver.findElement(By.id("a2")).click(); assertEquals(2, webConnection.getRequestCount()); driver.findElement(By.id("a3")).click(); assertEquals(2, webConnection.getRequestCount()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * Test case for issue #1492.//from w w w. jav a2 s.c om * * @throws Exception if the test fails */ @Test @Alerts({ "#!board/WebDev", "#!article/WebDev/35", "#!article/WebDev/35" }) public void dontReloadHashBang2() throws Exception { final String html = "<html>\n" + "<head><title>foo</title></head>\n" + "<body>\n" + " <a href='" + URL_FIRST + "test/#!board/WebDev' id='a1'>link1</a>\n" + " <a href='" + URL_FIRST + "test/#!article/WebDev/35' id='a2'>link2</a>\n" + " <a href='" + URL_FIRST + "test#!article/WebDev/35' id='a3'>link2</a>\n" + " <script>\n" + " alert(document.getElementById('a1').hash);\n" + " alert(document.getElementById('a2').hash);\n" + " alert(document.getElementById('a3').hash);\n" + " </script>\n" + "</body></html>"; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setDefaultResponse(html); final WebDriver driver = loadPageWithAlerts2(html); assertEquals(1, webConnection.getRequestCount()); driver.findElement(By.id("a1")).click(); assertEquals(2, webConnection.getRequestCount()); verifyAlerts(driver, getExpectedAlerts()); driver.findElement(By.id("a2")).click(); assertEquals(2, webConnection.getRequestCount()); driver.findElement(By.id("a3")).click(); assertEquals(3, webConnection.getRequestCount()); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @throws Exception if the test fails/* w w w .j a va2 s. c o m*/ */ @Test @Alerts(DEFAULT = { "URLbug.html?h%F6=G%FCnter", "h\ufffd", "G\ufffdnter" }, IE = { "URLbug.html?h\u00F6=G\u00FCnter", "h\ufffd", "G\ufffdnter" }) public void encoding() throws Exception { final String html = "<html>\n" + "<head>\n" + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + "</head>\n" + "<body>\n" + " <a href='bug.html?h\u00F6=G\u00FCnter' id='myLink'>Click me</a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(html, "text/html", UTF_8); expandExpectedAlertsVariables(URL_FIRST); final WebDriver driver = loadPage2(html, URL_FIRST); driver.findElement(By.id("myLink")).click(); assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl()); final List<NameValuePair> requestedParams = getMockWebConnection().getLastWebRequest() .getRequestParameters(); assertEquals(1, requestedParams.size()); assertEquals(getExpectedAlerts()[1], requestedParams.get(0).getName()); assertEquals(getExpectedAlerts()[2], requestedParams.get(0).getValue()); }