$$
The $$
command is a short way to call the findElements
command in order
to fetch multiple elements on the page similar to the $$
command from the browser scope. The difference when calling
it from an element scope is that the driver will look within the children of that element.
info
For more information on how to select specific elements, check out the Selectors guide.
Usage
$(selector).$$(selector)
Parameters
Name | Type | Details |
---|---|---|
selector | String , Function , Matcher | selector, JS Function, or Matcher object to fetch multiple elements |
Examples
- Asynchronous Mode
- Synchronous Mode
index.html
<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>
$.js
it('should get text a menu link', async () => {
const text = await $('#menu');
console.log(await text.$$('li')[2].$('a').getText()); // outputs: "API"
});
it('should get text a menu link - JS Function', async () => {
const text = await $('#menu');
console.log(await text.$$(function() { // Arrow function is not allowed here.
// this is Element https://developer.mozilla.org/en-US/docs/Web/API/Element
// in this particular example it is HTMLUListElement
// TypeScript users may do something like this
// return (this as Element).querySelectorAll('li')
return this.querySelectorAll('li'); // Element[]
})[2].$('a').getText()); // outputs: "API"
});
index.html
<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>
$.js
it('should get text a menu link', () => {
const text = $('#menu');
console.log(text.$$('li')[2].$('a').getText()); // outputs: "API"
});
it('should get text a menu link - JS Function', () => {
const text = $('#menu');
console.log(text.$$(function() { // Arrow function is not allowed here.
// this is Element https://developer.mozilla.org/en-US/docs/Web/API/Element
// in this particular example it is HTMLUListElement
// TypeScript users may do something like this
// return (this as Element).querySelectorAll('li')
return this.querySelectorAll('li'); // Element[]
})[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.