菜单
开源

content()

获取页面的 HTML 内容。

返回值

类型描述
Promise<string | null>一个 Promise,它在页面 HTML 内容以字符串形式或属性不存在时以 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');
  console.log(await page.content()); // HTML content printed in the console
}