Types Of Xpaths

Selenium Element Locators, Inspecting Elements, Selenium WebDriver API Commands and Writing Selenium Test Cases.
Post Reply
sekhar
Posts: 47
Joined: Mon Dec 31, 2018 6:40 am

Types Of Xpaths

Post by sekhar » Sat Jan 05, 2019 7:16 am

How Many Types Of Xpaths?

kishore
Posts: 55
Joined: Thu Jan 03, 2019 3:57 am

Re: Types Of Xpaths

Post by kishore » Mon Jan 07, 2019 4:35 am

There are two types of XPath:
=========================
1) Absolute XPath

2) 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.

Ex: html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b

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 start from the middle of the HTML DOM structure and no need to write long XPath.

Ex: Relative xpath: //*[@class='featured-box']//*[text()='Testing']

Post Reply

Return to “Selenium WebDriver”