List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs// ww w. j a v a 2 s . c o m */ @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()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * @throws Exception if an error occurs//from ww w . j a v a2 s .c om */ @Test public void length() throws Exception { final String second = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='length' href='' onclick='alert(history.length);return false;'>length</a><br>\n" + "<a name='x' href='#x'>x</a><br>\n" + "</body></html>\n"; getMockWebConnection().setResponse(URL_SECOND, second); final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='length' href='' onclick='alert(history.length);return false;'>length</a><br>\n" + "<a name='b' href='" + URL_SECOND + "'>b</a><br>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("length")).click(); // when testing with real browsers we are facing different offsets final int start = Integer.parseInt(getCollectedAlerts(driver, 1).get(0)); driver.findElement(By.name("b")).click(); driver.findElement(By.name("length")).click(); assertEquals(new String[] { "" + (start + 1) }, getCollectedAlerts(driver, 1)); driver.findElement(By.name("x")).click(); driver.findElement(By.name("length")).click(); assertEquals(new String[] { "" + (start + 2) }, getCollectedAlerts(driver, 1)); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * History.previous was defined in old FF versions. * * @throws Exception if an error occurs// w w w . ja v a2 s . c o m */ @Test @Alerts("undefined") public void previous() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='itemZero' href='' onclick='alert(history.previous); return false;'>item zero</a>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("itemZero")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * History.current was defined in old FF versions. * * @throws Exception if an error occurs//w w w .ja v a 2 s .c o m */ @Test @Alerts("undefined") public void current() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='itemZero' href='' onclick='alert(history.current); return false;'>item zero</a>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("itemZero")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * History.next was defined in old FF versions. * * @throws Exception if an error occurs/* www . j a v a 2 s .com*/ */ @Test @Alerts("undefined") public void next() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='itemZero' href='' onclick='alert(history.next); return false;'>item zero</a>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("itemZero")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * History.item was defined in old FF versions. * * @throws Exception if an error occurs//www .jav a 2s . co m */ @Test @Alerts("undefined") public void item() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='itemZero' href='' onclick='alert(history.item); return false;'>item zero</a>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("itemZero")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * @throws Exception if an error occurs// w ww . j a v a2 s. co m */ @Test @Alerts({ "false", "false", "false", "false", "false", "false" }) public void byIndex() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='hasNegativeOne' href='' onclick=" + "'alert(\"-1\" in history);alert(-1 in history);return false;'>has negative one</a><br>\n" + "<a name='hasZero' href='' onclick=" + "'alert(\"0\" in history);alert(0 in history);return false;'>has zero</a><br>\n" + "<a name='hasPositiveOne' href='' onclick=" + "'alert(\"1\" in history);alert(1 in history);return false;'>has positive one</a><br>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("hasNegativeOne")).click(); verifyAlerts(driver, getExpectedAlerts()[0]); driver.findElement(By.name("hasZero")).click(); verifyAlerts(driver, getExpectedAlerts()[1]); driver.findElement(By.name("hasPositiveOne")).click(); verifyAlerts(driver, getExpectedAlerts()[2]); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.History2Test.java
License:Apache License
/** * @throws Exception if an error occurs/*from w ww . j a v a 2s . c o m*/ */ @Test @Alerts("undefined") public void arrayAccess() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<a name='arrayAccess' href='' onclick='alert(history[0]);return false;'>array access</a><br>\n" + "</body></html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("arrayAccess")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLAnchorElement2Test.java
License:Apache License
/** * @throws Exception if the test fails/*from w ww . j av a 2 s.c o m*/ */ @Test @Alerts({ "URLtestsite1.html", "testsite1.html", "URLtestsite2.html", "testsite2.html", "13", "testanchor", "mailto:" }) public void getAttribute_and_href() throws Exception { final String html = "<html><head><title>AnchorTest</title>\n" + "<script>\n" + " function doTest(anchorElement) {\n" + " alert(anchorElement.href);\n" + " alert(anchorElement.getAttribute('href'));\n" + " anchorElement.href='testsite2.html';\n" + " alert(anchorElement.href);\n" + " alert(anchorElement.getAttribute('href'));\n" + " alert(anchorElement.getAttribute('id'));\n" + " alert(anchorElement.getAttribute('name'));\n" + " var link2 = document.getElementById('link2');\n" + " alert(link2.href);\n" + " }\n</script>\n" + "</head>\n" + "<body>\n" + " <a href='testsite1.html' id='13' name='testanchor' onClick='doTest(this);return false'>bla</a>\n" + " <a href='mailto:' id='link2'>mail</a>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); driver.findElement(By.name("testanchor")).click(); expandExpectedAlertsVariables(URL_FIRST); verifyAlerts(driver, getExpectedAlerts()); }
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 ava 2s.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 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()); }