Mouse
Added in: v1.8The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
TIP
If 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.
page.mouse().move(0, 0);
page.mouse().down();
page.mouse().move(0, 100);
page.mouse().move(100, 100);
page.mouse().move(100, 0);
page.mouse().move(0, 0);
page.mouse().up();Methods
mouse.click()
Added in: v1.8Shortcut for mouse.move(), mouse.down(), mouse.up().
Arguments
X coordinate relative to the main frame's viewport in CSS pixels.
Y coordinate relative to the main frame's viewport in CSS pixels.
mouse.dblclick()
Added in: v1.8Shortcut for mouse.move(), mouse.down(), mouse.up(), mouse.down() and mouse.up().
Arguments
X coordinate relative to the main frame's viewport in CSS pixels.
Y coordinate relative to the main frame's viewport in CSS pixels.
mouse.down()
Added in: v1.8Dispatches a mousedown event.
Arguments
mouse.move()
Added in: v1.8Dispatches a mousemove event.
Arguments
X coordinate relative to the main frame's viewport in CSS pixels.
Y coordinate relative to the main frame's viewport in CSS pixels.
mouse.up()
Added in: v1.8Dispatches a mouseup event.
Arguments
mouse.wheel()
Added in: v1.15Dispatches a wheel event. This method is usually used to manually scroll the page. See scrolling for alternative ways to scroll.
INFO
Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.
Arguments