跳至主要內容

custom$

custom$ 允許您使用透過 browser.addLocatorStrategy 宣告的自訂策略。 閱讀選取器文件中關於自訂選取器策略的更多資訊。

用法
$(selector).custom$(strategyName, strategyArguments)
參數
名稱類型詳細資訊
strategyName字串
strategyArguments參數
範例
customStrategy.js
loading...
example.html
loading...
customStrategy.js
loading...
example.js
it('should fetch the project title', async () => {
await browser.url('https://webdriverio.dev.org.tw')
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 AI Copilot