With the help of XPath's in selenium we can easily navigate through any HTML Structure of page. Every element on the page is not always written using same type of HTML attributes, so to handle every case we have different types of XPath's. This post discusses each of them. | Avni

editor-img
Avni
Aug 24, 2022

With the help of XPath's in selenium we can easily navigate through any HTML Structure of page. Every element on the page is not always written using same type of HTML attributes, so to handle every case we have different types of XPath's. This post discusses each of them.

Types of XPath's in Selenium : A. Absolute XPath - This is the simplest type of XPath in selenium wherein define element's path starting from the root. For example, if we have to select nested div till 2 levels, so for that absolute xpath will be - html/body/div/div[2]. Here, using selenium we are fetching 2nd div inside another div.

B. Relative XPath - Here, we define only the exact path for the element. If we have multiple forms in a page, with the help of relative path we break our xpath. This break while writing xpath, we denote it using double slash. For example, //form/input. Here, using this type we are breaking the xpath so that it will just look for this section from whole body.


Checkout related posts on: