New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: fetch elements within shadow root with shadow$
and shadow$$
#6314
Proposal: fetch elements within shadow root with shadow$
and shadow$$
#6314
Conversation
👍 I think this is a great step for testing web components. Always picking the first instance found is fine here I think. One concern I have with this is that it makes tests very brittle, and tightly coupled to private APIs of web components. You have the specify the entire path of all the elements. When you build your whole application out of web components, you have a lot of implementation details in your tests. In traditional webpages, people are used to being able to select elements by just using some landmarks such as ids, element names, form references or data attributes. With shadow dom this used by possible with the I think something like this is necessary to have, but it doesn't fully address all the use cases. So I wouldn't close all the related issues. There should also be a way to query elements deeply, such as implemented by libraries like https://github.com/Georgegriff/query-selector-shadow-dom |
Pinging @mathiasbynens @johanbay @paullewis on this as they've worked on the query handler parts more than me 👍 |
Thanks for kicking off this discussion, @christian-bromann! As a general note, building on top of the existing custom query handler infrastructure makes a lot of sense 👍 This PR lets you select across a single shadow root by explicitly referencing it. That's indeed better than anything we support out of the box right now. But, I think where we want to go eventually is a little different: as a user, I want to either select using the default magic ( WDYT? |
What can we do to move forward with this? |
@LarsDenBakker I haven't been able to follow up on this but will take some time this week to address @mathiasbynens comment. |
@mathiasbynens is this PR still useful? Or is the work than @johanbay has been doing now going to enable this more easily? |
With the changes to the query handler infrastructure, we can do something like this #6509 to support querying elements inside shadow roots. |
Yep that works for me. |
Sounds good to me too? Shall we close this PR then? |
Yes it sounds like we can close this one and merge #6509. Thanks! |
There are various issues on missing support for fetching elements within the shadow DOM of elements. Some related issues are:
Also for Puppeteer embedder projects like WebdriverIO:
This PR proposes
shadow$
andshadow$$
to allow query an element through element shadow roots. Given the following DOM structure:Given someone would fetch the root of an shadow element:
The following queries would give following results:
null
because we would always pick the first element being founddiv.container
One idea could be to always use
Element.querySelectorAll
and iterate through all nodes. This could be potentially a very expensive operation though and would only make sense forshadow$$
.WDYAT?