(If you don’t tell us what the children are, we cant give you a more specific selector to find said child. Your question has nothing to do with Shadow roots, it’s just asking how to select that third-depth child, which is a generalized problem.)
then querySelector(“.a > div > div > *:nth-child(1)”) would find the third-depth child. (I am assuming that the third depth child is randomized, otherwise you’d just search for the specific element name.)
[EDIT: also if the first and/or second depth elements have siblings, you may need to specify :nth-child(1) on them also.]
Which one is the “first”? A comes first if you’re reading the page top to bottom (Depth First), B comes first if you’re reading the page by levels (Breadth First).
I think that I don’t want to select the shadow root itself; I want to select any node that comes after node A, but just before the shadow root that follows node A.
This tells me you’re fundamentally misunderstanding what the shadow-root is.
shadowRoot is a property of an Element that links that element to a shadow-DOM. It’s not an element unto itself.
This… isnt a valid format. At least not in my browser.
EITHER:
the shadowRoot property of the parent is set, in which case the structure upon observation (assuming the shadow root was set to an Open view) would look like
<div></div>
<ow-j3eolsu49kg> <-- note, opening tag only....
#shadow-root
What you’re telling me there is that the shadowRoot property of the “odd” element is set.
So what you’d be looking for is the first element in the set of siblings whose shadowRoot was not null.
Again, AFAIK CSS cant select this property, so querySelector sadly will not be of assistance here.
[...document.getElementById("parent").children].filter(x => x.shadowRoot)[0]
(substitute in however you find the parent element)