Skip to main content

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

click

def click(
x,
y,
button: nil,
clickCount: nil,
delay: nil)

Shortcut for Mouse#move, Mouse#down, Mouse#up.

dblclick

def dblclick(x, y, button: nil, delay: nil)

Shortcut for Mouse#move, Mouse#down, Mouse#up, Mouse#down and Mouse#up.

down

def down(button: nil, clickCount: nil)

Dispatches a mousedown event.

move

def move(x, y, steps: nil)

Dispatches a mousemove event.

up

def up(button: nil, clickCount: nil)

Dispatches a mouseup event.

wheel

def wheel(deltaX, deltaY)

Dispatches a wheel event. This method is usually used to manually scroll the page. See scrolling for alternative ways to scroll.

NOTE: Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.