List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w . j a va2 s.c o m*/ */ @Test public void submit() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1' method='post'>\n" + "<input type='submit' name='aButton' value='foo'/>\n" + "<input type='suBMit' name='button' value='foo'/>\n" + "<input type='submit' name='anotherButton' value='foo'/>\n" + "</form></body></html>"; final WebDriver wd = loadPageWithAlerts2(html); final WebElement button = wd.findElement(By.name("button")); button.click(); assertEquals("foo", wd.getTitle()); assertEquals(Collections.singletonList(new NameValuePair("button", "foo")), getMockWebConnection().getLastParameters()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails/*from ww w . jav a 2 s .com*/ */ @Test @Alerts({ "foo", "bar" }) public void click_onClick() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1' onSubmit='alert(\"bar\"); return false;'>\n" + " <input type='submit' name='button' value='foo' onClick='alert(\"foo\")'/>\n" + "</form></body></html>"; final WebDriver webDriver = loadPage2(html); final WebElement button = webDriver.findElement(By.name("button")); button.click(); verifyAlerts(webDriver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w . jav a2 s . co m*/ */ @Test @Alerts("2") public void doubleSubmission() throws Exception { final String html = "<html>\n" + "<head>\n" + " <script type='text/javascript'>\n" + " function submitForm() {\n" + " document.deliveryChannelForm.submitBtn.disabled = true;\n" + " document.deliveryChannelForm.submit();\n" + " }\n" + " </script>\n" + "</head>\n" + "<body>\n" + " <form action='test' name='deliveryChannelForm'>\n" + " <input name='submitBtn' type='submit' value='Save' title='Save' onclick='submitForm();'>\n" + " </form>\n" + "</body>\n" + "</html>"; getMockWebConnection().setDefaultResponse(""); final WebDriver webDriver = loadPage2(html); final WebElement input = webDriver.findElement(By.name("submitBtn")); input.click(); assertEquals(Integer.parseInt(getExpectedAlerts()[0]), getMockWebConnection().getRequestCount()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails//from ww w. ja va 2 s . c om */ @Test public void doubleSubmissionWithRedirect() throws Exception { final String html = "<html><body>\n" + "<script>\n" + "function submitForm(btn) {\n" + " btn.form.submit();\n" + " btn.disabled = true;\n" + "}\n" + "</script>\n" + "<form method='post' action='test'>\n" + " <input name='text' type='text'>\n" + " <input name='btn' type='submit' onclick='submitForm(this);'>\n" + "</form>\n" + "</body></html>"; final MockWebConnection mockWebConnection = getMockWebConnection(); final List<NameValuePair> redirectHeaders = Arrays.asList(new NameValuePair("Location", "/nextPage")); mockWebConnection.setResponse(new URL(URL_FIRST, "test"), "", 302, "Found", null, redirectHeaders); mockWebConnection.setResponse(new URL(URL_FIRST, "nextPage"), "<html><head><title>next page</title></head></html>"); final WebDriver wd = loadPageWithAlerts2(html); final WebElement input = wd.findElement(By.name("btn")); input.click(); assertEquals("next page", wd.getTitle()); assertEquals(3, mockWebConnection.getRequestCount()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * @throws Exception if an error occurs/*from www.j a va2 s .c om*/ */ @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//from w ww . j ava 2s.c o m */ @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 ww. jav a2 s .c om*/ */ @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 ava 2 s . co m */ @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/*from ww 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//from w w w . j a va 2s . c om */ @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()); }