Is there a way to extract the XPATH of an html element in Javascript in runtime?

I’m developing an extension that allows the user to select an element and then highlight it whenever he visits the website, is there a way to programmatically get the xpath of an element?

I tried using classes, ids and tagnames but its not a reliable way to identify an element because its not guaranteed to exist.

>Solution :

There is a existent extension that can do the job for you but if you want to develop your own solution you can refer to this question

Leave a Reply