List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement2Test.java
License:Apache License
/** * Document.write after setting innerHTML. * @throws Exception if the test fails/*from w ww . ja v a 2 s . c o m*/ */ @Test @Alerts("hello") public void setInnerHTMLDocumentWrite() throws Exception { final String html = "<html>\n" + "<head><title>test</title></head>\n" + "<body>\n" + "<script>\n" + " var a = document.createElement('a');\n" + " a.innerHTML = 'break';\n" + " document.write('hello');\n" + "</script></body></html>"; final WebDriver driver = loadPage2(html); assertEquals(getExpectedAlerts()[0], driver.findElement(By.tagName("body")).getText()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w . j a v a 2 s . co m*/ */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationReplaceOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location.replace('content.html')\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id=\"frameOrder\"></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); final boolean ie = getBrowserVersion().isIE(); verifyAlerts(driver, "Body alert."); if (!ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().defaultContent(); if (ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails//ww w .j ava 2s. co m */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationAssignOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location.assign('content.html')\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id='frameOrder'></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); final boolean ie = getBrowserVersion().isIE(); verifyAlerts(driver, "Body alert."); if (!ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().defaultContent(); if (ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails// w w w. j ava 2 s.c o m */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationSetOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location='content.html'\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id='frameOrder'></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); if (StringUtils.isNotEmpty(getExpectedAlerts()[2])) { driver.findElement(By.name("onloadFrameAnchor")).click(); driver.switchTo().defaultContent(); driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElementTest.java
License:Apache License
/** * Test that field delegates submit to the containing form. * @throws Exception if the test fails//from w w w . j a va 2 s.co m */ @Test public void onChangeCallsFormSubmit() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "</head>\n" + "<body>\n" + " <form name='test' action='foo'>\n" + " <input name='field1' onchange='submit()'>\n" + " <img src='unknown.gif'>\n" + " </form>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse("<html><title>page 2</title><body></body></html>"); final WebDriver driver = loadPage2(html); driver.findElement(By.name("field1")).sendKeys("bla"); driver.findElement(By.tagName("img")).click(); assertEquals("page 2", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails// w w w . ja v a 2s.c o m */ @Test public void deselectFromMultiple() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); WebElement option = options.get(0); assertTrue(option.isSelected()); option.click(); assertFalse(option.isSelected()); option.click(); assertTrue(option.isSelected()); option = options.get(2); assertTrue(option.isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w . j ava 2 s . c o m*/ */ @Test public void optionClick() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); options.get(0).click(); assertFalse(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails//w w w . j a v a 2s .co m */ @Test // https://github.com/mozilla/geckodriver/issues/584 @BuggyWebDriver(FF) public void optionClickActions() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); new Actions(driver).click(options.get(0)).perform(); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertFalse(options.get(2).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java
License:Apache License
/** * @throws Exception if the test fails//from w ww. ja v a 2 s . c o m */ @Test @Alerts(DEFAULT = { "", "foo3.html", "foo2.html" }, CHROME = { "", "foo2.html" }) public void onlick_set_location_WithHref() throws Exception { final String html = "<html><head></head>\n" + "<body>\n" + " <a href='foo2.html' onclick='document.location = \"foo3.html\"'>click me</a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); driver.findElement(By.tagName("a")).click(); assertEquals(getExpectedAlerts(), getMockWebConnection().getRequestedUrls(URL_FIRST)); assertEquals(URL_FIRST + "foo2.html", driver.getCurrentUrl()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java
License:Apache License
/** * @throws Exception if the test fails//from w w w .jav a 2 s . c o m */ @Test @Alerts({ "", "foo3.html" }) public void onlick_set_location_WithoutHref() throws Exception { final String html = "<html><head></head>\n" + "<body>\n" + " <a onclick='document.location = \"foo3.html\"'>click me</a>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPage2(html); driver.findElement(By.tagName("a")).click(); assertEquals(getExpectedAlerts(), getMockWebConnection().getRequestedUrls(URL_FIRST)); assertEquals(URL_FIRST + "foo3.html", driver.getCurrentUrl()); }