What is the difference between absolute and relative xpaths? What is preferred when testing Selenium automation?

What is the difference between absolute and relative xpaths? What is preferred when testing Selenium automation? I am preparing test scripts using the Selenium and Robot framework.

+4
source share
3 answers

Absolute Xpath . It uses the full path from the root element to the desire element.

Relative xpath . You can simply start with a link to the desired item and go from there.

Xpath , Root. (//html//body). webelement /, Xpath. Relative Xpaths .

, .

+5

xpath HTML DOM /html, .

/html/body/div[5]/div[2]/div/div[2]/div[2]/h2[1]

xpath id dom xpath, , .

.//*[@id='answers']/h2[1]/a[1]

firepath (firebug) xpaths

, xpath , , ( )

xpaths , DOM

+4

HTML

<html>
  <body>
    <input type ="text" id="username">
  </body>

</html>

Absoulte= html/body/input =//* [@id = " " ]

The disadvantage with an absolute xpath is that the service is high if there is a change in the html that might break the whole way, and sometimes we need to write long absolute xpaths, so relative xpaths are preferred

+1
source

All Articles