Tuesday, August 2, 2016

Difference between Absolute (“/”) and Relative (“//”) in Xpath?



Absolute Xpath => Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

 Absolute xpath: /html/body/div[2]/div/div/footer/section[3]/div/ul/li[3]/a

Relative Xpath => Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.



 Relative xpath: //body//section[3]/div/ul/li[3]/a


Absolute xpaths are prone to more regression as slight change in DOM makes them invalid or refer to a wrong element

No comments:

Post a Comment