Skip to main content

custom$$

Overview​

Find multiple elements with a registered custom strategy. Use Array.from in the strategy when a DOM API returns a NodeList.

Usage​

browser.custom$$(strategyName, ...strategyArguments)

Parameters​

ParameterTypeDefaultDescription
strategyNamestringRequiredThe name of a registered strategy.
strategyArgumentsunknown[][]Arguments passed to the browser-side strategy.

Result​

An awaitable collection resolving to an array of WebdriverIO.Element objects. No matches produces an empty array.

Limitations​

An unknown strategy name throws an error. The command returns the matches found at the time of the query; it does not wait for a required number of elements.

Example​

Set baseUrl to your local HTTP test site, where / returns an HTML page. Run the example in a regular Testplane test file.

const assert = require("node:assert/strict");

it("custom$$: find several elements", async ({ browser }) => {
await browser.url("/");
await browser.execute(() => {
document.body.innerHTML = "<ul><li>First</li><li>Second</li></ul>";
});
browser.addLocatorStrategy("byCss", selector =>
Array.from(document.querySelectorAll(selector)),
);
const items = await browser.custom$$("byCss", "li");
assert.equal(items.length, 2);
assert.equal(await items[1].getText(), "Second");
});

See also​