Mouse Actions
Modifier clicks, clicking at a position, drawing, scrolling the wheel and dragging a slider: the low-level mouse API.
Clicks with modifier keys
click({ modifiers }) holds keys during the click. ControlOrMeta is Ctrl on Windows and Linux and Cmd on macOS, so one test runs everywhere.
const files = page.getByRole('listbox', { name: 'Files' });
await files.getByRole('option', { name: 'contract.pdf' }).click();
await files.getByRole('option', { name: 'notes.txt' }).click({ modifiers: ['Shift'] });
await files.getByRole('option', { name: 'photo.jpg' }).click({ modifiers: ['ControlOrMeta'] });Clicking a point inside an element
A canvas has no elements inside it to locate. Click a position relative to its top-left corner instead:
const map = page.getByRole('img', { name: 'Seat map' });
await map.click({ position: { x: 140, y: 90 } }); // seat B3Drawing: down, move, up
page.mouse works in page coordinates. Get the element's box first, and move in several steps so the app sees a line, not a jump. boundingBox() is measured from the visible window, so scroll the element into view before you use it:
const pad = page.getByRole('img', { name: 'Signature pad' });
await pad.scrollIntoViewIfNeeded(); // the mouse only reaches what is on screen
const box = (await pad.boundingBox())!;
await page.mouse.move(box.x + 20, box.y + 60);
await page.mouse.down();
await page.mouse.move(box.x + 250, box.y + 80, { steps: 10 });
await page.mouse.up();The wheel scrolls whatever is under the mouse
await page.getByTestId('zoom-box').hover();
await page.mouse.wheel(0, -100); // negative deltaY = scroll upclick() whenever you can. Coordinates break when the layout changes, so use them only where nothing else works: canvases, drawing, sliders.Select files
Click to select one file. Shift+click selects a range; Ctrl+click (⌘+click on a Mac) adds or removes one.
- budget.xlsx
- contract.pdf
- logo.png
- notes.txt
- report.docx
- photo.jpg
No files selected
Seat map
Rows A–E run top to bottom, seats 1–8 left to right. Each seat is 40×40 px with a 10 px gap, starting 20 px from the corner. Grey seats are taken.
No seats selected
Signature pad
Draw a line at least 150 px long.
Signature: empty
Zoom with the wheel
Scroll up over the box to zoom in, down to zoom out (50–200%).
Zoom: 100%
Volume slider
Drag the handle. The value snaps to steps of 10.
Volume: 30