I would like to be able to get the non-absolute css path of an element using Javascript so that I can subsequently call:
document.querySelectorAll()
I am trying to grab all elements from a page who share the same css path.
For example using the search results page from Google:
- A css selector (absolute) would be:
div.g:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1) > h3:nth-child(1) > div:nth-child(1)
- A css path (non-absolute) would be:
html body#gsr.srp.tbo.vasq div#main div#cnt div.mw div#rcnt div.col div#center_col div#res.med div#search div div#rso div.bkWMgd div.srg div.g div div.rc div.r a h3.LC20lb div.ellip
Every answer I have seen usually returns the absolute path (css selector) to an element - i.e the nth child. For example: Get CSS path from Dom element.
Does anyone have an idea on how to get just the pure css path which would be applicable to multiple elements on the page?
Edit: What I am really looking for is the source code in the Firefox Web Developer Inspector tool where you can right click and choose 'Copy CSS Path'. If someone has a pointer to this I would appreciate it.