跳到主要内容

$$

$$ 命令是一种简短方便的方式,用于获取页面上的多个元素。 它返回一个包含一组 WebdriverIO 元素的 ChainablePromiseArray

在使用 wdio 测试运行器时,此命令是一个全局变量,更多信息请参见 Globals。 在 独立 脚本中使用 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)
参数
名称类型详情
selectorString, Function用于获取多个元素的选择器或 JS 函数
示例
example.html
loading...
multipleElements.js
loading...
multipleElements.js
loading...
multipleElements.js
loading...
返回值
  • <WebdriverIO.ElementArray>

Welcome! How can I help?

WebdriverIO AI Copilot