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()

Methods

click

Added before v1.9 mouse.click

Shortcut for mouse.move(), mouse.down(), mouse.up().

Usage

mouse.click(x, y)
mouse.click(x, y, **kwargs)

Arguments

  • x float#

    X coordinate relative to the main frame's viewport in CSS pixels.

  • y float#

    Y coordinate relative to the main frame's viewport in CSS pixels.

  • button "left" | "right" | "middle" (optional)#

    Defaults to left.

  • click_count int (optional)#

    defaults to 1. See UIEvent.detail.

  • delay float (optional)#

    Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.

Returns


dblclick

Added before v1.9 mouse.dblclick

Shortcut for mouse.move(), mouse.down(), mouse.up(), mouse.down() and mouse.up().

Usage

mouse.dblclick(x, y)
mouse.dblclick(x, y, **kwargs)

Arguments

  • x float#

    X coordinate relative to the main frame's viewport in CSS pixels.

  • y float#

    Y coordinate relative to the main frame's viewport in CSS pixels.

  • button "left" | "right" | "middle" (optional)#

    Defaults to left.

  • delay float (optional)#

    Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.

Returns


down

Added before v1.9 mouse.down

Dispatches a mousedown event.

Usage

mouse.down()
mouse.down(**kwargs)

Arguments

  • button "left" | "right" | "middle" (optional)#

    Defaults to left.

  • click_count int (optional)#

    defaults to 1. See UIEvent.detail.

Returns


move

Added before v1.9 mouse.move

Dispatches a mousemove event.

Usage

mouse.move(x, y)
mouse.move(x, y, **kwargs)

Arguments

  • x float#

    X coordinate relative to the main frame's viewport in CSS pixels.

  • y float#

    Y coordinate relative to the main frame's viewport in CSS pixels.

  • steps int (optional)#

    Defaults to 1. Sends intermediate mousemove events.

Returns


up

Added before v1.9 mouse.up

Dispatches a mouseup event.

Usage

mouse.up()
mouse.up(**kwargs)

Arguments

  • button "left" | "right" | "middle" (optional)#

    Defaults to left.

  • click_count int (optional)#

    defaults to 1. See UIEvent.detail.

Returns


wheel

Added in: v1.15 mouse.wheel

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.

Usage

mouse.wheel(delta_x, delta_y)

Arguments

  • delta_x float#

    Pixels to scroll horizontally.

  • delta_y float#

    Pixels to scroll vertically.

Returns