DEV Community

Discussion on: Generate a CSS selector path of a DOM element.

Collapse
 
disgustingdev profile image
disgusting-dev

Fella, if you are about to create xPath generator, I suggest you to create browser extension for this - I believe there will be a lot of those QA guys who need as fast as possible to get in clipboard such an xpath for e2e testing (yes, I'm talking about those who don't use test ids) - and much better if it defines id or data-id etc. of element and minimize your path just to it

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

It already uses the id if you look at the code, first thing it checks for and returns early if found.

Plus this is used as part of an analytics package to track clicks, the being able to click on things is just to demonstrate.

If you wanted you could easily turn it into a bookmarklet and have the ID copied to the clipboard, no need to build a browser extension for something so simple, especially when you can get the Xpath with developer tools really easily.