Skip to main content
Page keyboard methods for the Playwright driver.

keyboard.down

Dispatches a keydown event.
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.Modifier keys DO affect keyboard.down. Holding down Shift will type the text in upper case.
Upstream docs
key
string
required
Name of the key to press or a character to generate, such as ArrowLeft or a.
await page.keyboard.down('...');

keyboard.up

Dispatches a keyup event. Upstream docs
key
string
required
Name of the key to release or a character.
await page.keyboard.up('...');

keyboard.press

Shortcut for keyboard.down() and keyboard.up().
Dispatches a keydown, keypress/input, and keyup event for the specified key.If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also be generated.Modifier keys DO affect keyboard.press. Holding down Shift will type the text in upper case.Shortcut such as “ControlOrMeta+A” are supported. “ControlOrMeta” resolves to “Control” on Windows/Linux and to “Meta” on macOS.
Upstream docs
key
string
required
Key to press. Can be a character or a special key name (e.g., ArrowLeft, Shift+A, ControlOrMeta+A).
options
PlaywrightKeyboardPressOptions
Options for the key press event.
await page.keyboard.press('...');

keyboard.type

Sends a keydown, keypress/input, and keyup event for each character in the text.
Use this method when you need to simulate typing character by character, for example, if the page has custom keyboard event listeners.Modifier keys DO NOT affect keyboard.type. Holding down Shift will not type the text in upper case.For characters not present on a standard US keyboard layout, only an input event will be dispatched.For simple text input, locator.fill() is generally preferred.
Upstream docs
text
string
required
Text to type.
options
PlaywrightKeyboardTypeOptions
Options for typing.
await page.keyboard.type('...');

keyboard.insertText

Dispatches only an input event, does not emit keydown, keyup, or keypress events.
This method is useful for directly inserting text without simulating physical key presses.Modifier keys DO NOT affect keyboard.insertText. Holding down Shift will not type the text in upper case.
Upstream docs
text
string
required
Text to insert.
await page.keyboard.insertText('...');