Closed OrKoN closed 1 year ago
The Browser Testing and Tools Working Group just discussed Shadow DOM selectors in WebDriver (BiDi)
.
I believe the conclusion is that this sort of functionality should be up to the clients to implement. Closing the issue.
WebDriver provides multiple strategies for querying selectors but none of the strategies allows querying across shadow roots in one request. Querying elements inside shadow roots is a common automation task that is especially relevant for automated testing. The question how query elements inside shadow roots is asked often and the way that is currently recommended is to do querying step by step (first select the host, then select element inside the host's shadow root and so on). It means that element selector cannot be captured with a single selector. Instead, querying elements in shadow roots is a mix of multiple selectors and code. On top of that, various frameworks might offer different ways to deal with the problem and invent custom and largely incompatible syntaxes. Approaches we have seen so far:
1) storing a list of selectors to indicate that each of the selector (except for the last one) identifies the shadow DOM host. 2) re-defining the behaviour for the CSS combinators such as the child/descendant 3) storing the entire JS code to query the shadow DOM elements.
We think there might be an opportunity for WebDriver to standardize the syntax for combining selectors to indicate the queries for shadow DOM elements. It could be potentially included into the WebDriver BiDi and WebDriver Classic standards.
One proposal would be to support the
>>>
(deep descendant combinator) and>>>>
(deep child combinators) in CSS selectors to indicate shadow roots in a query. The deep descendant combinator was previously defined in the webcomponents spec but was removed: https://github.com/WICG/webcomponents/issues/78One way would be to support something similar to CSS extensions spec: https://drafts.csswg.org/css-extensions/ but it might clash with the actually CSS implementation.
One requirement to consider is that extending the CSS selectors might not be sufficient. Ideally, the syntax allows combining multiple locator strategies in one query. For example, the shadow host might be selected using CSS and the element inside it's shadow root using text selectors. For example, using the
>>>
syntax that would apply to multiple strategies:div > some-host >>> link-text-strategy("my link text")
.Initially, we think that syntax should only work for open shadow roots. So far, we have not received the feedback that querying closed shadow roots is desirable. Since closed shadow roots are not accessible via DOM APIs, this kind of selectors probably should allow querying them as well.