2

I need to get absolute Xpath and not the relative one.

I need something like this:

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

On both browsers when I inspect the code and I use right click -> copy XPath I am getting the relative Path.

Any tool or plugin available to get absolute path.

Please note, I am using selenium webdriver.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
qa testing
  • 51
  • 1
  • 3
  • 2
    https://stackoverflow.com/a/49396361/5752558 Does this answer help you? – Nathan Jan 29 '20 at 07:05
  • 2
    You have `copy full xpath` option. But you should use the relative xpath, not the absolute xpath. – Guy Jan 29 '20 at 07:09
  • Does this answer your question? [How to get Absolute XPath in Chrome or Firefox?](https://stackoverflow.com/questions/48022185/how-to-get-absolute-xpath-in-chrome-or-firefox) – Alejandro Jan 29 '20 at 15:46

3 Answers3

3

To get the absolute path in: Chrome Browser (v79): Right-click WebPage -> Inspect -> Right-click on web element -> Copy -> Copy Full Xpath (This gives you absolute XPath)

Firefox browser (v72): Right-click webpage -> Inspect Element -> Right-click on web element -> Copy -> XPath (If the web element has any unique id then it will give you the relative XPath otherwise it will give absolute XPath). To get the absolute XPath for an element having a unique id, delete the unique id in the inspector window and again copy the XPath you will get the absolute XPath.

Sathish
  • 350
  • 3
  • 24
1

To retrive the absolute from the Browser Console you can follow the steps mentioned below:

  1. Open the url https://demoqa.com/button/ in Google Chrome browser.
  2. Press F12 or Shift + Ctrl + I to open the .
  3. Within Elements tab, click on the element Inspector tool:

element_inspector

  1. Mouse Hover over the desired element and the element gets highlighted within the DOM Tree

desired_element

  1. Right Click on the element within the HTML, select Copy and select Copy XPath

copy_xpath

  1. You will get the absolute xpath as:

    //*[@id="content"]/div[2]/div/input
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Why you want Absolute Xpath. If you want to locate with Xpath only then highly recommended Relative Xpath.

Absolute Xpath will change if your current UI change(html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b) . Like if added extra div or section or any element.