← Back to library
Playwrightformsintermediatev1.20+
Trigger keyboard shortcuts
Press modifier key combinations like Ctrl+A and Ctrl+C on a focused element.
1test('selects all text and copies with keyboard shortcuts', async ({ page }) => {
2 await page.goto('/editor');
3
4 const editor = page.getByRole('textbox', { name: 'Content' });
5 await editor.fill('Hello World');
6
7 // press() accepts KeyboardEvent.key names and modifier combos
8 await editor.press('Control+a'); // select all text
9 await editor.press('Control+c'); // copy to clipboard
10
11 // Paste into a second field to verify the clipboard content
12 const preview = page.getByRole('textbox', { name: 'Preview' });
13 await preview.click();
14 await preview.press('Control+v');
15
16 await expect(preview).toHaveValue('Hello World');
17});#keyboard#ctrl#shortcut#press#hotkey