Monday 5 March 2018

Published March 05, 2018 by

An Overview on xPath

Hello learners,

xPath is a very famous technique for locating elements on a webpage. Sometimes we can not find elements having complex selectors that time xpath is very useful for locating such elements. So, in this post, we’ll learn about what is 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: