Press keyboard shortcuts
Send key combinations and special keys with press, and know when to use fill instead.
press() sends one keystroke or one combination to an element. Use it for shortcuts and special keys such as Enter, Escape, and Tab. Use fill() when you want to set a field's text, not simulate typing.
Press a combination on a focused element
press() takes a single key string. Join modifiers with +. The element is focused first, then the combination is sent.
$page->goto('https://app.example.test/editor');
$editor = $page->getByRole('textbox', ['name' => 'Document body']);
$editor->press('Control+A');
$editor->press('Control+C');
Modifier names are Control, Shift, Alt, and Meta. On macOS, many app shortcuts use Meta where other platforms use Control.
Send special keys
Special keys use their named form, not the character they produce.
$page->getByRole('searchbox')->press('Enter');
$page->getByRole('dialog')->press('Escape');
$page->getByLabel('First name')->press('Tab');
Enter submits or confirms, Escape dismisses, Tab moves focus to the next control. Arrow keys are ArrowDown, ArrowUp, ArrowLeft, and ArrowRight.
Type text with fill, not press
To put a value in a field, use fill(). It clears the field and sets the text in one step, and it does not fire a keystroke per character.
// Set the value directly.
$page->getByLabel('Email')->fill('ada@example.test');
// Press only when a keystroke is the point, such as submitting.
$page->getByLabel('Email')->press('Enter');
Reach for per-character typing only when the page reacts to each keystroke. press() sends one key; fill() sets the whole value.
Drive keyboard at the page level
When no single element is the target, the page keyboard sends keys to whatever holds focus.
$page->keyboard()->press('Control+S');
keyboard() also exposes down(), up(), and type() for held keys and free-form text. Prefer a locator's press() when you know which element should receive the key.
Pitfalls
press('Control+A')is one call, notpress('Control')thenpress('A'). Separate presses release the modifier between keys.- A special key must use its name.
press('Enter')works;press('\n')does not. - If a shortcut does nothing, the wrong element may hold focus. Press on the specific locator, or focus it first.
Expected result
The shortcut changes the page state it is meant to change: saved content, submitted search, closed dialog, or moved focus. Assert that outcome instead of only sending the key.