0

in chrome I get a xpath value: //*[@id='user_change_pw_form']/div[3]/span

and for the same element in firebug I get: /html/body/div[2]/form/div[3]/span

why do I have to speparate the xpath queries like that to get one and the same element in Selenium testcase:

switch (System.getProperty("test.driver")) 
        {
            case "chrome":
            case "html":
                text = driver.findElement(By.xpath("//*[@id='user_change_pw_form']/div[3]/span")).getText();


            case "gecko":
                text = driver.findElement(By.xpath("/html/body/div[2]/form/div[3]/span")).getText(); 
                break;

        }

While the respective counterpart gives for the wrong browser "Unable to locate element", though both xpath queries work in both browser consoles.

Thanks in advance!

Leder
  • 396
  • 1
  • 5
  • 21

2 Answers2

1

Try writing your own xPaths / CSS selectors rather than relying on browser based selectors. This link would help you learn/write your own selectors.

I would also suggest using css selectors over xpaths since they are more readable.

Kenil Fadia
  • 234
  • 3
  • 7
1

firefox has absolute xpath and cannot handle chrome's xpath.

Thanks to @noor and @Kenil Fadia

Leder
  • 396
  • 1
  • 5
  • 21