textContent([options])
返回 element.textContent
。
参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
options | object | null | |
options.timeout | number | 30000 | 最大时间(毫秒)。传递 0 可禁用超时。默认值将被 BrowserContext 或 Page 上的 setDefaultTimeout 选项覆盖。 |
返回值
类型 | 说明 |
---|---|
Promise<null | string> | 返回一个 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 options = page.locator('#checkbox1');
console.log(await options.textContent());
}