Mouse
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
tipIf you want to debug where the mouse moved, you can use the Trace viewer or Playwright Inspector. A red dot showing the location of the mouse will be shown for every mouse action.
Every page object has its own Mouse, accessible with page.mouse.
// Using ‘page.mouse’ to trace a 100x100 square. await page.mouse.move(0, 0); await page.mouse.down(); await page.mouse.move(0, 100); await page.mouse.move(100, 100); await page.mouse.move(100, 0); await page.mouse.move(0, 0); await page.mouse.up();
Methods
click
Added before v1.9Shortcut for mouse.move(), mouse.down(), mouse.up().
Usage
await mouse.click(x, y); await mouse.click(x, y, options);
Arguments
-
xnumberX coordinate relative to the main frame's viewport in CSS pixels.
-
ynumberY coordinate relative to the main frame's viewport in CSS pixels.
-
optionsObject (optional)-
button"left" | "right" | "middle" (optional)Defaults to
left. -
clickCountnumber (optional)defaults to 1. See UIEvent.detail.
-
delaynumber (optional)Time to wait between
mousedownandmouseupin milliseconds. Defaults to 0.
-
Returns
dblclick
Added before v1.9Shortcut for mouse.move(), mouse.down(), mouse.up(), mouse.down() and mouse.up().
Usage
await mouse.dblclick(x, y); await mouse.dblclick(x, y, options);
Arguments
-
xnumberX coordinate relative to the main frame's viewport in CSS pixels.
-
ynumberY coordinate relative to the main frame's viewport in CSS pixels.
-
optionsObject (optional)-
button"left" | "right" | "middle" (optional)Defaults to
left. -
delaynumber (optional)Time to wait between
mousedownandmouseupin milliseconds. Defaults to 0.
-
Returns
down
Added before v1.9Dispatches a mousedown event.
Usage
await mouse.down(); await mouse.down(options);
Arguments
-
optionsObject (optional)-
button"left" | "right" | "middle" (optional)Defaults to
left. -
clickCountnumber (optional)defaults to 1. See UIEvent.detail.
-
Returns
move
Added before v1.9Dispatches a mousemove event.
Usage
await mouse.move(x, y); await mouse.move(x, y, options);
Arguments
-
xnumberX coordinate relative to the main frame's viewport in CSS pixels.
-
ynumberY coordinate relative to the main frame's viewport in CSS pixels.
-
optionsObject (optional)-
stepsnumber (optional)Defaults to 1. Sends
ninterpolatedmousemoveevents to represent travel between Playwright's current cursor position and the provided destination. When set to 1, emits a singlemousemoveevent at the destination location.
-
Returns
up
Added before v1.9Dispatches a mouseup event.
Usage
await mouse.up(); await mouse.up(options);
Arguments
-
optionsObject (optional)-
button"left" | "right" | "middle" (optional)Defaults to
left. -
clickCountnumber (optional)defaults to 1. See UIEvent.detail.
-
Returns
wheel
Dispatches a wheel event. This method is usually used to manually scroll the page. See scrolling for alternative ways to scroll.
noteWheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.
Usage
await mouse.wheel(deltaX, deltaY);
Arguments
Returns
© 2026 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-mouse