MarketSquare / MarketSquare/robotframework-browser

Add `Dispatch Event` keyword to fire DOM events on an element

Open
#5,107 0 comments 0 reactions 1 assignee View on GitHub

@Snooz82 is already working on this.

Since Aug 6, 2026.

enhancement
Dominant language
Python
Stars
655
Forks
147
Avg merge
5h 27m
Merged PRs (30d)
59

Description

## Use case

Some events simply cannot be produced by real user-input keywords: application-defined custom events, `dragstart`/`dragend` on exotic drag implementations, synthetic `change`/`input` events on components that swallow real input, `deviceorientation`, and similar. Today the only escape hatch is hand-written `Evaluate JavaScript` such as `(e) => e.dispatchEvent(new Event('change'))` — which gets none of Playwright's benefits: no auto-waiting for the element to be attached, no strict-mode selector resolution, and no automatic mapping of the event type to the correct event class (`MouseEvent`, `DragEvent`, `TouchEvent`, …) with properly initialized properties.

Playwright covers this with `dispatchEvent`, available both element-scoped (locator) and page-scoped; a single selector-based keyword covers both use cases since the library addresses elements by selector anyway.

## Proposed keyword / arguments

`Dispatch Event selector event eventInit=&{EMPTY} *, timeout=None`

- `selector` — element to receive the event (strict-mode resolved, auto-waits for attachment; supports `->>` frame piercing like other element keywords).
- `event` — DOM event type, e.g. `click`, `dragstart`, `change`, or a custom event name.
- `eventInit` — dictionary passed to the event constructor (Playwright picks `DragEvent`, `MouseEvent`, etc. based on the event type and composes it accordingly).
- `timeout` — maximum wait time for the element; library timeout when omitted.

```robotframework
Dispatch Event id=source dragstart
Dispatch Event css=.widget app:refresh
&{init}= Create Dictionary bubbles=${True} cancelable=${True}
Dispatch Event id=form-field change ${init}
Get Text id=status == changed
```

## Playwright API

- [`locator.dispatchEvent`](https://playwright.dev/docs/api/class-locator#locator-dispatch-event)
- [`page.dispatchEvent`](https://playwright.dev/docs/api/class-page#page-dispatch-event) (same capability, addressed via selector — covered by the one keyword)

## Implementation notes

- New RPC in `protobuf/playwright.proto` (selector, event type, serialized eventInit, timeout/strict).
- `node/playwright-wrapper`: resolve the locator with the existing selector machinery and call `locator.dispatchEvent(event, eventInit)`.
- Python keyword in `Browser/keywords/interaction.py`, docs, atest cases including a custom event and an event carrying `eventInit` data.

## Backwards compatibility

Purely additive: a new keyword; existing `Evaluate JavaScript` workarounds keep working unchanged.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.