-4

I am trying to get Absolute path of an webelement element in Java , Currently I have tried using FirePath it always gives me relative Path ..Can anyone help me out in this or there is another way to manually write Absolute path of web element ...Thank u in Advance

Varun.S
  • 39
  • 2
  • 11
  • First of all correct your question, FirePath can't provide you relative xpath. It always give absolute xpath. – Indrapal Singh Feb 27 '18 at 12:01
  • Possible duplicate of [how to inspect element in selenium3.6 as firebug is not an option any more for FF 56?](https://stackoverflow.com/questions/46700764/how-to-inspect-element-in-selenium3-6-as-firebug-is-not-an-option-any-more-for-f/46702281#46702281) – undetected Selenium Feb 27 '18 at 13:05

1 Answers1

4

If you want to become expert in Xpath then better you practice with different approaches I am just adding here.

Xpath or xml path :

It can be created in two different ways 1.Absolute Xpath 2.Relative Xpath

Absolute Xpath is starts from root of html page to the element with prefix ‘/’. It is less preferable because it can create trouble for you if there is some change in UI.

Relative Xpath :It starts with the double forward slash (//), which means it can search the element anywhere at the webpage. It is most preferable.

1.Using any attributes(id,class,value and name etc.) -> //tagName[@attribute=’’]

2.Using attributes with contains //tagName[contains(@attribute,’’)]

3.Using text //tagName[text()=’’]

4.Using text with contains //tagName[contains(text(),’’)]

5.Using starts-with //tagName[starts-with(@attribute,’’)]

6.Using axis

a) following -> Select all input after attribute

//tagName[@attribute=’’]//following::tagName

b) following-sibling -> Select sibling element

//tagName[@attribute=’’]//following-sibling::tagName

c) ancestor -> Select ancestor of current element

//tagName[@attribute=’’]//ancestor::tagName

d)child -> select child of current element

//tagName[@attribute=’’]//child::tagName

e)Preceding -> Select preceding elements

//tagName[@attribute=’’]//preceding::tagName

f) Parent -> Select parent of current element

//tagName[@attribute=’’]//parent::tagName

Hope this will help you.

Indrapal Singh
  • 364
  • 1
  • 2
  • 13