Pretty straightforward. I think I have what should be a unique selector, but in Chrome it returns two <p> elements. The page I’m looking at is:
http://docs.webfaction.com/user-guide/control_panel.html
and the selector is:
document.querySelectorAll('body:nth-child(2) div#container:nth-child(1) div#content.clear.hasCorners:nth-child(2) div.document:nth-child(3) div.documentwrapper:nth-child(1) div.bodywrapper:nth-child(1) div.body:nth-child(1) div#the-control-panel.section:nth-child(1) p:nth-child(3)')
I must be misunderstanding something about the nth-child selector because I would think this is guaranteed to be unique.
EDIT: Ah, I should definitely be using some child selectors (>) here to avoid going further down the DOM tree. Someone can feel free to answer it with that and I’ll accept.
As noted above, the issue is that without the child selector (
>) there’s no guarantee of uniqueness because there may be additional matches further down the DOM tree. For instance consider this markup:if you tried:
that would return two elements.