菜单
开源

textContent([options])

返回 element.textContent

参数类型默认值说明
optionsobjectnull
options.timeoutnumber30000最大时间(毫秒)。传递 0 可禁用超时。默认值将被 BrowserContextPage 上的 setDefaultTimeout 选项覆盖。

返回值

类型说明
Promise<null | string>返回一个 Promise,它使用选择器的文本内容或 null 来兑现。

示例

JavaScript
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());
}