跳到主要内容

custom$

custom$ 允许您使用通过 browser.addLocatorStrategy 声明的自定义策略。 在选择器文档中阅读更多关于自定义选择器策略的信息。

用法
$(selector).custom$(strategyName, strategyArguments)
参数
名称类型详情
strategyNamestring
strategyArguments*
示例
customStrategy.js
loading...
example.html
loading...
customStrategy.js
loading...
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 header = await browser.custom$('myStrat', 'header')
const projectTitle = await header.custom$('myStrat', '.projectTitle')

console.log(projectTitle.getText()) // WEBDRIVER I/O
})
返回值
  • <WebdriverIO.Element>

Welcome! How can I help?

WebdriverIO AI Copilot