inputValue([options])
返回所选 input
、textarea
或 select
元素的 input.value
。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
options | 对象 | null | |
options.timeout | 数字 | 30000 | 最大时间,单位毫秒。传入 0 可禁用超时。默认值会被 BrowserContext 或 Page 上的 setDefaultTimeout 选项覆盖。 |
返回值
类型 | 描述 |
---|---|
Promise<string> | 一个 Promise,成功时返回元素的输入值。 |
示例
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 = await page.$('#text1');
await textInput.fill('Hello world!');
console.log(await textInput.inputValue());
await page.close();
}