菜单
开源

inputValue([options])

返回所选 inputtextareaselect 元素的 input.value

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

返回值

类型描述
Promise<string>一个 Promise,该 Promise 会以元素的输入值兑现。

示例

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 textInput = page.locator('#text1');
  await textInput.fill('Hello world!');
  console.log(await textInput.inputValue());
}