Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is a existent extension that can do the job for you https://www.npmjs.com/package/xpath-retriever but if you want to develop your own solution you can refer to this question https://stackoverflow.com/a/5178132/18317391

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading