Absolute XPath: The XPath starts Root node with following a hierarchy to the element with corresponding nodes from the page. nodes path represent like ‘/’.
Eg : html/body/div/div/input
Note: absolute XPath is not recommended for better element location If any add/change in the nodes the hierarchy should be changed and we can get the proper location for an element.
Relative XPath: The XPath should construct with particular element related attributes(element characteristic). it represents like “//”.
And Finally many plugins available to get proper XPaths.
Eg: firepath, Testsigma(chrome)
Testsigma Chrome extension will give very unique and simplest paths.
In Selenium, XPath is nothing but the XML Path. It helps in locating any element on a web page that uses traditional XML path expression. XPath uses HTML DOM structure that looks like XML path expression.
Xpath are of two types as follows:
- Absolute Xpath: It is the most straight forward way of locating a web element but the demerit for the absolute Xpath is that it gets failed when there are any changes made in the Xpath of the web element on the HTML document. It has a characteristic that it begins with a single forward slash character (‘/’) i.e. selecting an element starting from the root node. Following is the syntax cum example for an absolute XPath expression of the element:
- Relative Xpath: For this type of Xpath, the path begins from the middle of the HTML DOM (Document Object model) structure. It has a characteristic that it begins with a double forward slash character (‘//’) i.e. selecting a web element from anywhere of the web page. It has a benefit to begin from the middle of the HTML DOM structure and abstain from writing long XPath starting from the root node. Following is the syntax cum example for a relative XPath expression of the element:
Relative xpath: //[@class=’class-test-box’]//
Have a look at this link for more Automation details.