What is the difference between relative and absolute XPath

0 votes
I was using XPath for locating an element and came to know there are two kinds of XPath. Can someone help me distinguish between them and tell me as which of the two is better for testing purpose?
Dec 19, 2018 in Selenium by Jino
• 5,820 points
67,158 views

3 answers to this question.

+1 vote

Absolute Xpath: It contains the complete path from the Root Element to the desire element.

Relative Xpath: This is more like starting simply by referencing the element you want and go from the particular location.

You use always the Relative Path for testing of an element. The reason behind that is if you make any architectural change in the website the change won't effect the testing or selecting of the element.

Hope this information was what you were looking for. For more details about test automation strategies and methodology, You can get a better understanding with the Automation testing training.

answered Dec 20, 2018 by Nabarupa
0 votes

Relative - the element is positioned relative to its normal position. Absolute - the element is positioned absolutely to its first positioned parent. Fixed - the element is positioned related to the browser window.

answered Dec 16, 2020 by Roshni
• 10,520 points
0 votes

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.

Relative Xpath:

Relative Xpath starts from the middle of HTML DOM structure. It starts with double forward slash (//). It can search elements anywhere on the webpage, means no need to write a long xpath and you can start from the middle of HTML DOM structure. Relative Xpath is always preferred as it is not a complete path from the root element.

Hope this helps!

Want to learn more about Xpath? Enroll for the Selenium course today!

answered Dec 16, 2020 by Gitika
• 65,890 points

Related Questions In Selenium

0 votes
1 answer

What is the difference between dot and text() in XPath?

Even though there is some difference between ...READ MORE

answered Apr 25, 2018 in Selenium by king_kenny
• 3,710 points
8,270 views
0 votes
1 answer

What is the primary difference between the XPath and CSS selector?

Hello Ushma, the primary difference between XPath ...READ MORE

answered Jun 24, 2019 in Selenium by Anvi
• 14,150 points

edited Oct 27, 2023 by Khan Sarfaraz 32,816 views
0 votes
1 answer

What is the difference between thoughtworks.selenium and openqa.selenium selenium?

thoughtworks.selenium is the original Selenium (aka Selenium 1, ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,710 points
2,962 views
0 votes
1 answer

What is difference the between Selenium and Celerity?

If you are talking about speed, use Celerity. If ...READ MORE

answered Apr 20, 2018 in Selenium by king_kenny
• 3,710 points
991 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,567 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,084 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,178 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,840 views
0 votes
2 answers

What is the difference between / and // in xpath?

/ - Selects from the root node // ...READ MORE

answered May 29, 2019 in Selenium by anonymous
28,192 views
0 votes
1 answer

What is the difference between test scenarios, test cases and test script?

Difference between test scenarios and test cases ...READ MORE

answered Jan 28, 2019 in Selenium by Frankie
• 9,830 points
13,795 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP