Back to Puppeteer

ElementHandle.press() method

website/versioned_docs/version-24.40.0/api/puppeteer.elementhandle.press.md

19.2.21.1 KB
Original Source

ElementHandle.press() method

Focuses the element, and then uses Keyboard.down() and Keyboard.up().

Signature

typescript
class ElementHandle {
  press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>;
}

Parameters

<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

key

</td><td>

KeyInput

</td><td>

Name of key to press, such as ArrowLeft. See KeyInput for a list of all key names.

</td></tr> <tr><td>

options

</td><td>

Readonly<KeyPressOptions>

</td><td>

(Optional)

</td></tr> </tbody></table>

Returns:

Promise<void>

Remarks

If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also be generated. The text option can be specified to force an input event to be generated.

NOTE Modifier keys DO affect elementHandle.press. Holding down Shift will type the text in upper case.