You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
querySelector that can pierce Shadow DOM roots without knowing the path through nested shadow roots. Useful for automated testing of Web Components e.g. with Selenium, Puppeteer.
4
4
5
+
querySelector that can pierce Shadow DOM roots without knowing the path through nested shadow roots. Useful for automated testing of Web Components e.g. with Selenium, Puppeteer.

17
19
You can see that `.dropdown-item:not([hidden])` (Open downloads folder) is several layers deep in shadow roots, most tools will make you do something like
- querySelectorAllDeep - mirrors `querySelectorAll` from the browser, will return an `Array` of elements matching the query
33
43
- querySelectorDeep - mirrors `querySelector` from the browser, will return the `first` matching element of the query.
34
44
- collectAllElementsDeep - collects all elements on the page, including shadow dom
35
45
36
46
Both of the methods above accept a 2nd parameter, see section `Provide alternative node`. This will change the starting element to search from i.e. it will find ancestors of that node that match the query.
37
47
38
48
## Known limitations
49
+
39
50
- Source ordering of results may not be preserved. Due to the nature of how this library works, by breaking down selectors into parts, when using multiple selectors (e.g. split by commas) the results will be based on the order of the query, not the order the result appear in the dom. This is different from the native `querySelectorAll` functionality. You can read more about this here: https://github.com/Georgegriff/query-selector-shadow-dom/issues/54
40
51
41
52
## Plugins
42
53
43
54
### WebdriverIO
55
+
44
56
This plugin implements a custom selector strategy: https://webdriver.io/docs/selectors.html#custom-selector-strategies
- From the above, firefox `setValue` does NOT currently work.
123
-
`. A workaround for now is to use a custom command (or method on your component object) that sets the input field's value via browser.execute(function).`
142
+
`. A workaround for now is to use a custom command (or method on your component object) that sets the input field's value via browser.execute(function).`
124
143
125
144
- Safari pretty much doesn't work, not really a surprise.
126
145
127
146
There are some webdriver examples available in the examples folder of this repository.
The plugin registers a new [locator](https://www.protractortest.org/#/api?view=ProtractorBy) - `by.shadowDomCss(selector /* string */)`, which can be used in regular Protractor tests:
177
196
178
197
```javascript
179
-
element(by.shadowDomCss('#item-in-shadow-dom'))
198
+
element(by.shadowDomCss("#item-in-shadow-dom"));
180
199
```
181
200
182
201
The locator also works with [Serenity/JS](https://serenity-js.org) tests that [use Protractor](https://serenity-js.org/modules/protractor) under the hood:
const ElementOfInterest =Target.the('element of interest')
190
-
.located(by.shadowDomCss('#item-in-shadow-dom'))
208
+
const ElementOfInterest =Target.the("element of interest").located(
209
+
by.shadowDomCss("#item-in-shadow-dom")
210
+
);
191
211
```
192
212
193
213
See the [end-to-end tests](https://github.com/Georgegriff/query-selector-shadow-dom/blob/features/protractor-locator/test/protractor-locator.e2e.js) for more examples.
This library does not allow you to query across iframe boundaries, you will need to get a reference to the iframe you want to interact with. </br>
206
230
If your iframe is inside of a shadow root you could cuse `querySelectorDeep` to find the iframe, then pass the `contentDocument` into the 2nd argument of `querySelectorDeep` or `querySelectorAllDeep`.
207
231
208
-
209
232
### Chrome downloads page
210
233
211
-
212
234
In the below examples the components being searched for are nested within web components `shadowRoots`.
213
235
214
236
```javascript
215
-
216
237
// Download and Paste the lib code in dist into chrome://downloads console to try it out :)
0 commit comments