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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…