RE: How to write Relative Xpath
To choose the relative xpath, it is advisable to look for the recent Id attribute. Look below at the HTML code of the above screen shot.
You can see the recent or last Id produced is ‘footer_nav‘. This id would be appropriate in this case, so a quality xpath will look like this: //*[@id=’social-media’]/ul/li/a
Did you notice the difference between the Absolute and Relative xpaths?
Absolute xpath: /html/body/div/div/div/footer/section/div/ul/li/a
Relative xpath: //*[@id=’social-media’]/ul/li/a
Here , I am not getting how you written Relative Xpath ?
Thank you all for voting.
@Murali: We have to be very specific while choosing the right Xpath as if there is any kind of duplicate in tags or its attribute the Xpath may fail to capture the element or might pickup any different element.
You can choose any Xpath that can be uniquely identified.Like for the above scenario you can also have the Xpaths like
1. //*[@title=’Get Fed on our Feeds’]
However in this case you have to be careful that the title = “Get Fed on our Feeds” OR
class “rss” must be present only once (where u r inspecting) on the page.