$$(selector)
在 ElementHandle 的子树中查询给定选择器的元素。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
selector | string | 用于查询元素的 CSS 选择器。 |
返回值
类型 | 描述 |
---|---|
Promise<null | ElementHandle[]> | 一个 Promise,它在找到元素时解析为 ElementHandle 数组。如果未找到元素,则 Promise 解析为 null 。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
await page.goto('https://test.k6.io/browser.php');
const elements = await page.$$('#text1');
for (const element of elements) {
// ...
}
await page.close();
}