new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

mouse & keyboard actions

18 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Frame.click() method signature and options

Frame.click() is an async method (discouraged, use Locator.click instead). It clicks an element matching the selector. Parameters: selector (required). Options: button (string), clickCount (number), delay (number), force (boolean), scroll (boolean), modifiers (array), noWaitAfter (boolean), position (object), strict (boolean), timeout (number), signal (AbortSignal), trial (boolean).

Frame.dblclick() method signature and options

Frame.dblclick() is an async method (discouraged, use Locator.dblclick instead). It double clicks an element matching the selector. Parameters: selector (required). Options: button (string), force (boolean), scroll (boolean), delay (number), modifiers (array), noWaitAfter (boolean), position (object), strict (boolean), timeout (number), signal (AbortSignal), trial (boolean). Note: frame.dblclick() dispatches two click events and a single dblclick event.

Frame.dispatchEvent() method signature

Frame.dispatchEvent() is an async method (discouraged, use Locator.dispatchEvent instead). It dispatches a DOM event on an element matching the selector. Parameters: selector (required), type (string, required - DOM event type like 'click' or 'dragstart'), eventInit (optional EvaluationArgument for event-specific properties). Options: strict (boolean), timeout (number), signal (AbortSignal).

Frame.dragAndDrop() method signature and options

Frame.dragAndDrop() is an async method. It performs a drag and drop operation. Parameters: source (selector, required), target (selector, required). Options: force (boolean), scroll (boolean), noWaitAfter (boolean), strict (boolean), timeout (number), signal (AbortSignal), trial (boolean), sourcePosition (object), targetPosition (object), steps (number).

Frame.hover() method signature and options

Frame.hover() is an async method (discouraged, use Locator.hover instead). It hovers over an element matching the selector. Parameters: selector (required). Options: position (object), modifiers (array), force (boolean), scroll (boolean), strict (boolean), timeout (number), signal (AbortSignal), trial (boolean), noWaitAfter (boolean).

Frame.press() method signature and options

Frame.press() is an async method (discouraged, use Locator.press instead). It presses a key in an element matching the selector. Parameters: selector (required), key (string, required - keyboardEvent.key value or single character). Options: delay (number, default 0), noWaitAfter (boolean), strict (boolean), timeout (number), signal (AbortSignal).

Frame.tap() method signature and options

Frame.tap() is an async method (discouraged, use Locator.tap instead). It taps an element matching the selector. Parameters: selector (required). Options: force (boolean), scroll (boolean), modifiers (array), noWaitAfter (boolean), position (object), strict (boolean), timeout (number), signal (AbortSignal), trial (boolean). Note: requires hasTouch option of the browser context to be set to true.

Frame.type() method signature and options

Frame.type() is an async method (deprecated, use Locator.fill or Locator.pressSequentially instead). It sends keydown, keypress/input, and keyup events for each character. Parameters: selector (required), text (string, required - text to type). Options: delay (number, default 0 - time to wait between key presses in milliseconds).

Frame.dispatchEvent() example with click

To dispatch a click event on an element: await frame.dispatchEvent('button#submit', 'click');

Frame press key with modifier example

Shortcuts such as key: "Control+o", key: "Control++" or key: "Control+Shift+T" are supported. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. Following modification shortcuts are also supported: Shift, Control, Alt, Meta, ShiftLeft, ControlOrMeta. ControlOrMeta resolves to Control on Windows and Linux and to Meta on macOS.

Page.dragAndDrop example with positions

Example showing how to use dragAndDrop with specific positions. Call await page.dragAndDrop('#source', '#target', { sourcePosition: { x: 34, y: 7 }, targetPosition: { x: 10, y: 20 } }). The positions are relative to the top-left corners of the elements.

Page.dispatchEvent example - dispatch click event

Example showing how to dispatch an event. Use await page.dispatchEvent('button#submit', 'click') to dispatch a click event on an element. This is equivalent to calling element.click().

Page.dispatchEvent example - dispatch drag event with DataTransfer

Example showing how to dispatch a drag event with a DataTransfer object. Use const dataTransfer = await page.evaluateHandle(() => new DataTransfer()), then call page.dispatchEvent('#source', 'dragstart', { dataTransfer }). JSHandle can be passed as event properties for live objects.

Page.hover method and options

Page.hover hovers over an element matching the selector. It performs: finding the element, waiting for actionability checks, scrolling into view if needed, and hovering over the center or specified position. Options: force, scroll, modifiers, position, strict, timeout, trial, noWaitAfter. This method is discouraged in favor of Locator.hover. Available since v1.8.

Page.press method and key parameter

Page.press focuses the element and then uses Keyboard.down and Keyboard.up. The key parameter can specify keyboardEvent.key value or a single character. Examples: F1-F12, Digit0-Digit9, KeyA-KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab, Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp. Supported modifiers: Shift, Control, Alt, Meta, ShiftLeft, ControlOrMeta. Shortcuts like 'Control+o', 'Control+Shift+T' are supported. This method is discouraged in favor of Locator.press.

Page.press options

Page.press options: delay (float, default 0 - time in milliseconds between keydown and keyup), noWaitAfter, strict, timeout, signal. Available since v1.8.

Page.tap method behavior

Page.tap taps an element matching selector by finding the element, waiting for actionability checks unless force option is set, scrolling into view if needed, and using Page.touchscreen to tap the center of the element or specified position. Throws TimeoutError if timeout is exceeded. Passing zero timeout disables this. Throws if Browser.newContext.hasTouch option is false.

Page.type method behavior

Page.type sends a keydown, keypress/input, and keyup event for each character in the text. It can be used to send fine-grained keyboard events. To fill values in form fields, use Page.fill. To press a special key like Control or ArrowDown, use Keyboard.press.

Give your agent this brain