Mouse
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
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
click
Added before v1.9Shortcut for Mouse.move(), Mouse.down(), Mouse.up().
Usage
Mouse.click(x, y);
Mouse.click(x, y, options);
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.
-
options
Mouse.ClickOptions
(optional)
Returns
dblclick
Added before v1.9Shortcut for Mouse.move(), Mouse.down(), Mouse.up(), Mouse.down() and Mouse.up().
Usage
Mouse.dblclick(x, y);
Mouse.dblclick(x, y, options);
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.
-
options
Mouse.DblclickOptions
(optional)
Returns
down
Added before v1.9Dispatches a mousedown
event.
Usage
Mouse.down();
Mouse.down(options);
Arguments
options
Mouse.DownOptions
(optional)-
setButton
enum MouseButton { LEFT, RIGHT, MIDDLE }
(optional)#Defaults to
left
. -
defaults to 1. See UIEvent.detail.
-
Returns
move
Added before v1.9Dispatches a mousemove
event.
Usage
Mouse.move(x, y);
Mouse.move(x, y, options);
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.
-
options
Mouse.MoveOptions
(optional)
Returns
up
Added before v1.9Dispatches a mouseup
event.
Usage
Mouse.up();
Mouse.up(options);
Arguments
options
Mouse.UpOptions
(optional)-
setButton
enum MouseButton { LEFT, RIGHT, MIDDLE }
(optional)#Defaults to
left
. -
defaults to 1. See UIEvent.detail.
-
Returns
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.
Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.
Usage
Mouse.wheel(deltaX, deltaY);
Arguments
Returns