I am having a very funny issue. I am having a xpath through which i am retrieving value.
Ex.
System.out.print(driver.findElement(By.xpath("//*[@id='error-box']/ul/li")).getText().toString());
In firefox and Chrome it is giving same text while in IE it is giving different text.
Is there any difference between xpath of various browser or it is some other issue which i am not getting.
Xpath is same across all browsers.
No, Chrome uses XPath 1.0. You can simplify your XPath expression to just a v2.
There are two types of XPath: Absolute XPath. Relative XPath.
Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari.
Read up on how Selenium handles Xpaths here.
In Chrome and Firefox, I right-clicked on the same DOM element (as described here), selected "copy Xpath" and this is what I got:
Chrome: //*[@id="js-pjax-container"]/div2/div2/form/button
Firefox (with Firebug): /html/body/div[4]/div2/div2/div2/form/button
(one is with attribute value and the other (FF) is the absolute path, which demonstrates that FF doesn't understand Crhome generated Xpath)
So for Selenium test purposes, it matters between browsers. (I didn't test on IE)
I ran this
@Test
public void testGitHubButton(){
WebDriver driver = new FirefoxDriver();
driver.get("https://github.com/");
String signup = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div[1]/div[1]/form/button")).getText();
Assert.assertEquals("Testing for string equality", "Sign up for GitHub", signup );
driver.close();
driver.quit();
}
And the test passes. If I copy paste Chrome's Xpath in there, it will fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With