What is the difference between relative and absolute XPath?


I was using XPath for locating an element and came to know there are two kinds of XPath. Can someone help me distinguish between them and tell me as which of the two is better for testing purpose?



The primary difference between XPath and CSS Selectors is that, with the XPath we can traverse both forward and backward whereas CSS selector only moves forward. Although CSS selectors performance is better than Xpath and it is well documented in the Selenium community. It possesses the following advantages over XPath as:

1.Xpath engines are found to be different in each browser, this makes and maintains inconsistency.
2.Internet Explorer does not have any specific native xpath engine, therefore selenium injects its own xpath engine for compatibility of its API. Thus losing the advantage of using native browser features.
3.Xpath tends to become complex and hence makes it hard to read.
However there are some situations where you need to use xpath, like while searching for a parent element or searching element by its text.




This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply
