$$
$$
命令是一種簡短且方便的方式,用於在頁面上提取多個元素。它會返回一個包含一組 WebdriverIO 元素的 ChainablePromiseArray
。
使用 wdio 測試執行器時,此命令是一個全域變數,詳情請參閱全域變數。在獨立腳本中使用 WebdriverIO 時,它將位於瀏覽器物件上(例如,browser.$$
)。
您可以將 $
或 $$
連結在一起,而無需將個別命令包裝在 await
中,以便向下遍歷 DOM 樹,例如:
const imageSrc = await $$('div')[1].nextElement().$$('img')[2].getAttribute('src')
也可以使用非同步迭代器來循環查詢結果,例如:
// print all image sources
for await (const img of $$('img')) {
console.log(await img.getAttribute('src'))
}
資訊
有關如何選擇特定元素的更多資訊,請查看選取器指南。
用法
browser.$$(selector)
參數
名稱 | 類型 | 詳細資訊 |
---|---|---|
selector | String 、Function | 用於提取多個元素的選取器或 JS 函式 |
範例
example.html
loading...
multipleElements.js
loading...
multipleElements.js
loading...
multipleElements.js
loading...