List of usage examples for org.openqa.selenium WebDriver findElement
@Override WebElement findElement(By by);
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
public static WebElement getInputItemByTypeAndName(WebDriver driver, String type, String name) { String xpath = "//input[@type='" + type + "' and @name='" + name + "']"; return driver.findElement(By.xpath(xpath)); }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
/*** * Gets image by alt text//www . j ava 2 s . c om * * @param driver * @param type * @return */ public static WebElement getImageByAltText(WebDriver driver, String altText) { String xpath = "//img[@alt='" + altText + "']"; return driver.findElement(By.xpath(xpath)); }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
/*** * Gets element by xpath/*from www . j ava 2 s . com*/ * * @param driver * @param xPath * @return */ public static WebElement getElementByXPath(WebDriver driver, String xPath) { return driver.findElement(By.xpath(xPath)); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails//from www . j a v a 2s. c o m */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) public void test() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<note>13109<to>Tove</to>13109<from>Jani</from>13109<body>Do32not32forget32me32this32weekend!</body>" + "13109<outer>131099<inner>Some32Value</inner></outer>1310</note>1310"; final String serializationText = "<note> " + "<to>Tove</to> \\n" + "<from>Jani</from> \\n " + "<body>Do not forget me this weekend!</body> " + "<outer>\\n " + " <inner>Some Value</inner>" + "</outer> " + "</note>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails/* w ww . jav a 2 s . c o m*/ */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) public void comment() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<a><!--32abc32--></a>1310"; final String serializationText = "<a><!-- abc --></a>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails//from www. j a v a2 s. c om */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) public void xmlEntities() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<a><>&</a>1310"; final String serializationText = "<a><>&</a>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails//from w w w . ja v a 2 s . c om */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) @NotYetImplemented(IE) // so far we are not able to add the XML header public void nameSpaces() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<?xml32version=\"1.0\"?>1310<xsl:stylesheet32version=\"1.0\"32" + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">13109<xsl:template32match=\"/\">131099<html>" + "1310999<body>1310999</body>131099</html>13109</xsl:template>1310</xsl:stylesheet>1310"; final String serializationText = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n" + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\\n" + " <xsl:template match=\"/\">\\n" + " <html>\\n" + " <body>\\n" + " </body>\\n" + " </html>\\n" + " </xsl:template>\\n" + "</xsl:stylesheet>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails//from ww w .j ava2 s . c o m */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) public void attributes() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<document32attrib=\"attribValue\"><outer32attrib=\"attribValue\">" + "<inner32attrib=\"attribValue\"/><meta32attrib=\"attribValue\"/></outer></document>1310"; final String serializationText = "<document attrib=\"attribValue\">" + "<outer attrib=\"attribValue\">" + "<inner attrib=\"attribValue\"/>" + "<meta attrib=\"attribValue\"/>" + "</outer></document>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLSerializerTest.java
License:Apache License
/** * @throws Exception if the test fails/*from ww w. j av a 2s.co m*/ */ @Test @Alerts(DEFAULT = "no ActiveX", IE = {}) @NotYetImplemented(IE) // so far we are not able to add the XML header public void htmlAttributes() throws Exception { final String expectedString = getExpectedAlerts().length != 0 ? "" : "<?xml32version=\"1.0\"?>1310<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>1310"; final String serializationText = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body id=\"bodyId\">" + "<span class=\"spanClass\">foo</span>" + "</body>" + "</html>"; final WebDriver driver = loadPageWithAlerts2(constructPageContent(serializationText)); final WebElement textArea = driver.findElement(By.id("myTextArea")); assertEquals(expectedString, textArea.getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.BrowserVersion2Test.java
License:Apache License
/** * @throws Exception if an error occurs/*from www. j a v a2s . co m*/ */ @Test @Alerts(DEFAULT = { "2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }, CHROME = { "2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" }, IE = { "2", "Accept: text/html, application/xhtml+xml, */*" }) public void acceptHeaderWindowOpen() throws Exception { String html = "<html><body>Response</body></html>"; getMockWebConnection().setDefaultResponse(html); html = "<html><head><title>First</title></head>\n" + "<body>\n" + " <a id='clickme' href='javascript: window.open(\"" + URL_SECOND + "\")'>Click me</a>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); driver.findElement(By.id("clickme")).click(); // because real browsers are doing the open async, we have to be a bit patient Thread.sleep(DEFAULT_WAIT_TIME); assertEquals(getExpectedAlerts()[0], Integer.toString(getMockWebConnection().getRequestCount())); assertEquals(getExpectedAlerts()[1], acceptHeaderString()); shutDownRealIE(); }