菜单
文档breadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/browserbreadcrumb arrow Framebreadcrumb arrow dispatchEvent(selector, type, eventInit[, options])
开源

dispatchEvent(selector, type, eventInit[, options])

警告

请使用基于 locator 的 locator.dispatchEvent(type, eventInit[, options]) 代替。

分派 HTML DOM 事件类型,例如 'click'

参数类型默认值描述
selectorstring''用于搜索元素的 CSS 选择器。如果存在多个满足选择器的元素,将使用第一个。
typestring''DOM event type e.g. 'click'.
eventInitobjectnull可选的事件特定属性。详情请参阅 eventInit
optionsobjectnull
options.strictbooleanfalsetrue 时,要求选择器只匹配单个元素。如果给定的选择器匹配多个元素,则调用会抛出异常。
options.timeoutnumber30000最大超时时间(毫秒)。传入 0 禁用超时。默认值会被 BrowserContextPage 上的 setDefaultTimeout 选项覆盖。

eventInit

由于 eventInit 是特定于事件的,请参考事件文档以获取初始属性列表

返回值

类型描述
Promise<void>一个 Promise,当事件被分派时会完成。