$$
The $$
command is a short way to call the findElements
command in order
to fetch multiple elements on the page. It returns an array with element results that will have an
extended prototype to call action commands without passing in a selector. However if you still pass
in a selector it will look for that element first and call the action on that element.
Using the wdio testrunner this command is a global variable else it will be located on the browser object instead.
You can chain $
or $$
together in order to walk down the DOM tree.
info
For more information on how to select specific elements, check out the Selectors guide.
Usage
browser.$$(selector)
Parameters
Name | Type | Details |
---|---|---|
selector | String , Function | selector or JS Function to fetch multiple elements |
Examples
- Asynchronous Mode
- Synchronous Mode
<ul id="menu">
<li><a href="/">Home</a></li>
<li><a href="/">Developer Guide</a></li>
<li><a href="/">API</a></li>
<li><a href="/">Contribute</a></li>
</ul>
it('should get text a menu link', async () => {
const text = await $$('#menu')[0];
console.log(await text.$$('li')[2].$('a').getText()); // outputs: "API"
});
it('should get text a menu link - JS Function', async () => {
const text = await $$(function() { // Arrow function is not allowed here.
// this is Window https://developer.mozilla.org/en-US/docs/Web/API/Window
// TypeScript users may do something like this
// return (this as Window).document.querySelectorAll('#menu')
return this.document.querySelectorAll('#menu'); // Element[]
})[0];
console.log(await text.$$('li')[2].$('a').getText()); // outputs: "API"
});
<ul id="menu">
<li><a href="/">Home</a></li>
<li><a href="/">Developer Guide</a></li>
<li><a href="/">API</a></li>
<li><a href="/">Contribute</a></li>
</ul>
it('should get text a menu link', () => {
const text = $$('#menu')[0];
console.log(text.$$('li')[2].$('a').getText()); // outputs: "API"
});
it('should get text a menu link - JS Function', () => {
const text = $$(function() { // Arrow function is not allowed here.
// this is Window https://developer.mozilla.org/en-US/docs/Web/API/Window
// TypeScript users may do something like this
// return (this as Window).document.querySelectorAll('#menu')
return this.document.querySelectorAll('#menu'); // Element[]
})[0];
console.log(text.$$('li')[2].$('a').getText()); // outputs: "API"
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.