custom$
The custom$
allows you to use a custom strategy declared by using browser.addLocatorStrategy
Usage
browser.custom$(strategyName, strategyArguments)
Parameters
Name | Type | Details |
---|---|---|
strategyName | String | |
strategyArguments | Any |
Example
- Asynchronous Mode
- Synchronous Mode
example.js
it('should fetch the project title', async () => {
await browser.url('https://webdriver.io')
await browser.addLocatorStrategy('myStrat', (selector) => {
return document.querySelectorAll(selector)
})
const projectTitle = await browser.custom$('myStrat', '.projectTitle')
console.log(await projectTitle.getText()) // WEBDRIVER I/O
})
example.js
it('should fetch the project title', () => {
browser.url('https://webdriver.io')
browser.addLocatorStrategy('myStrat', (selector) => {
return document.querySelectorAll(selector)
})
const projectTitle = browser.custom$('myStrat', '.projectTitle')
console.log(projectTitle.getText()) // WEBDRIVER I/O
})
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.