Published March 04, 2018 by

An Overview on xPath

An Overview on xPath

In this post, we’ll learn about xPath and types of xPaths.

What is xPath?

  • xPath stands for XML Path Language. 
  • It is used to navigate in XML documents to find nodes using different types of locators.
Different Types of xPath: 
xPath are categorized into two types: 
  • Absolute xPath and
  • Relative xPath
Absolute xPath:
  • It is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.
  • The key characteristic of XPath is that it begins with the single forward slash(/) ,which means you can select the element from the root node.
  • Below is the example of an absolute xpath expression of the element shown in the below screen.
A basic example of Absolute xPath:



Relative xPath:
  • For Relative Xpath the path starts from the middle of the HTML DOM structure. It starts with the double forward slash (//), which means it can search the element anywhere at the webpage.
  • You can starts from the middle of the HTML DOM structure and no need to write long xpath.
  • Below is the example of a relative XPath expression of the same element shown in the below screen. This is the common format used to find element through a relative XPath.
A basic example of Relative xPath:


Popular Posts