dispatchEvent(type, eventInit)
分派 HTML DOM 事件类型,例如 'click'
。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
type | string | '' | DOM 事件类型,例如 'click' 。 |
eventInit | object | null | 可选的事件特定属性。请参阅 eventInit 获取更多详细信息。 |
options | object | null | |
options.timeout | number | 30000 | 最大超时时间(毫秒)。传递 0 以禁用超时。默认值将被 BrowserContext 或 Page 上的 setDefaultTimeout 选项覆盖。 |
eventInit
由于 eventInit
是特定于事件的,请参考事件文档以获取初始属性列表
返回值
类型 | 描述 |
---|---|
Promise<void> | 事件分派后完成的 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 button = await page.$('#counter-button');
await button.dispatchEvent('click');
await page.close();
}