Method: Playwright::ElementHandle#dispatch_event

Defined in:
lib/playwright_api/element_handle.rb

#dispatch_event(type, eventInit: nil) ⇒ Object

The snippet below dispatches the ‘click` event on the element. Regardless of the visibility state of the element, `click` is dispatched. This is equivalent to calling [element.click()](developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).

“‘python sync element_handle.dispatch_event(“click”) “`

Under the hood, it creates an instance of an event based on the given ‘type`, initializes it with `eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.

Since ‘eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:

You can also specify ‘JSHandle` as the property value if you want live objects to be passed into the event:

“‘python sync # note you can only create data_transfer in chromium and firefox data_transfer = page.evaluate_handle(“new DataTransfer()”) element_handle.dispatch_event(“#source”, “dragstart”, data_transfer) “`



168
169
170
# File 'lib/playwright_api/element_handle.rb', line 168

def dispatch_event(type, eventInit: nil)
  wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit)))
end