List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:com.gargoylesoftware.htmlunit.html.HtmlSelect2Test.java
License:Apache License
/** * @exception Exception If the test fails *//*from w w w.j av a 2 s . c o m*/ @Test @BuggyWebDriver({ FF, IE }) public void select() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + " <option value='option1'>Option1</option>\n" + " <option value='option2'>Option2</option>\n" + " <option value='option3' selected='selected'>Option3</option>\n" + " <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>"; final WebDriver driver = loadPage2(html); final List<WebElement> options = driver.findElements(By.tagName("option")); final Actions actions = new Actions(driver); final Action selectThreeOptions = actions.click(options.get(1)).click(options.get(2)).click(options.get(3)) .build(); selectThreeOptions.perform(); assertFalse(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertFalse(options.get(2).isSelected()); assertTrue(options.get(3).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSelect2Test.java
License:Apache License
/** * @exception Exception If the test fails *//*from www. j a va2 s . c o m*/ @Test @BuggyWebDriver(IE) public void shiftClick() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + " <option value='option1'>Option1</option>\n" + " <option value='option2'>Option2</option>\n" + " <option value='option3' selected='selected'>Option3</option>\n" + " <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>"; final WebDriver driver = loadPage2(html); final List<WebElement> options = driver.findElements(By.tagName("option")); final Actions actions = new Actions(driver); final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.SHIFT).click(options.get(3)) .keyUp(Keys.SHIFT).build(); selectThreeOptions.perform(); assertFalse(options.get(0).isSelected()); assertTrue(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); assertTrue(options.get(3).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSelect2Test.java
License:Apache License
/** * @exception Exception If the test fails *///from w w w . j a va 2 s.co m @Test @BuggyWebDriver({ FF, IE }) public void controlClick() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + " <option value='option1'>Option1</option>\n" + " <option value='option2'>Option2</option>\n" + " <option value='option3' selected='selected'>Option3</option>\n" + " <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>"; final WebDriver driver = loadPage2(html); final List<WebElement> options = driver.findElements(By.tagName("option")); final Actions actions = new Actions(driver); final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.CONTROL).click(options.get(3)) .keyUp(Keys.CONTROL).build(); selectThreeOptions.perform(); assertFalse(options.get(0).isSelected()); assertTrue(options.get(1).isSelected()); assertFalse(options.get(2).isSelected()); assertTrue(options.get(3).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs//from w w w.j a v a 2 s. c o m */ @Test @Alerts("frame loaded") public void siblingWithoutContentBeforeFrameset() throws Exception { final String html = "<html>\n" + "<div><span></span></div>\n" + "<frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + "</frameset>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(1, webDriver.findElements(By.name("main")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs// ww w . jav a2s . c om */ @Test @Alerts("frame loaded") public void siblingWithWhitespaceContentBeforeFrameset() throws Exception { final String html = "<html>\n" + "<div> \t \r \r\n</div>\n" + "<frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + "</frameset>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(1, webDriver.findElements(By.name("main")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs//from w w w. j a v a 2 s . c o m */ @Test public void siblingWithNbspContentBeforeFrameset() throws Exception { final String html = "<html>\n" + "<div> </div>\n" + "<frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + "</div>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(0, webDriver.findElements(By.name("main")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs//from w w w . j av a 2 s . c om */ @Test public void siblingWithContentBeforeFrameset() throws Exception { final String html = "<html>\n" + "<div><span>CONTENT</span></div>\n" + "<frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + "</frameset>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(0, webDriver.findElements(By.name("main")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs/* w w w.ja v a 2 s . com*/ */ @Test @Alerts("frame loaded") @NotYetImplemented public void framesetInsideDiv() throws Exception { final String html = "<html>\n" + "<div id='tester'>\n" + " <frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + " </frameset>\n" + "</div>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(1, webDriver.findElements(By.name("main")).size()); assertEquals(0, webDriver.findElements(By.id("tester")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs/*w ww . ja v a 2 s. c o m*/ */ @Test @Alerts("frame loaded") @NotYetImplemented public void framesetInsideForm() throws Exception { final String html = "<html>\n" + "<form id='tester'>\n" + " <frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + " </frameset>\n" + "</form>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(1, webDriver.findElements(By.name("main")).size()); assertEquals(0, webDriver.findElements(By.id("tester")).size()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs/*ww w .j a va 2 s. c om*/ */ @Test @NotYetImplemented public void framesetInsideTable() throws Exception { final String html = "<html>\n" + "<table id='tester'>\n" + " <frameset>\n" + " <frame name='main' src='" + URL_SECOND + "' />\n" + " </frameset>\n" + "</table>\n" + "</html>"; final String html2 = "<html><body>\n" + "<script>\n" + " alert('frame loaded');\n" + "</script>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals(0, webDriver.findElements(By.name("main")).size()); assertEquals(1, webDriver.findElements(By.id("tester")).size()); }