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

Mouse.click(x, y[, options])

Added in: v1.8
  • x <double>#
  • y <double>#
  • options <Mouse.ClickOptions>
    • setButton <enum MouseButton { LEFT, RIGHT, MIDDLE }> Defaults to left.#
    • setClickCount <int> defaults to 1. See UIEvent.detail.#
    • setDelay <double> Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.#
  • returns: <void>#

Shortcut for Mouse.move(x, y[, options]), Mouse.down([options]), Mouse.up([options]).

Mouse.dblclick(x, y[, options])

Added in: v1.8
  • x <double>#
  • y <double>#
  • options <Mouse.DblclickOptions>
    • setButton <enum MouseButton { LEFT, RIGHT, MIDDLE }> Defaults to left.#
    • setDelay <double> Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.#
  • returns: <void>#

Shortcut for Mouse.move(x, y[, options]), Mouse.down([options]), Mouse.up([options]), Mouse.down([options]) and Mouse.up([options]).

Mouse.down([options])

Added in: v1.8
  • options <Mouse.DownOptions>
    • setButton <enum MouseButton { LEFT, RIGHT, MIDDLE }> Defaults to left.#
    • setClickCount <int> defaults to 1. See UIEvent.detail.#
  • returns: <void>#

Dispatches a mousedown event.

Mouse.move(x, y[, options])

Added in: v1.8
  • x <double>#
  • y <double>#
  • options <Mouse.MoveOptions>
    • setSteps <int> Defaults to 1. Sends intermediate mousemove events.#
  • returns: <void>#

Dispatches a mousemove event.

Mouse.up([options])

Added in: v1.8
  • options <Mouse.UpOptions>
    • setButton <enum MouseButton { LEFT, RIGHT, MIDDLE }> Defaults to left.#
    • setClickCount <int> defaults to 1. See UIEvent.detail.#
  • returns: <void>#

Dispatches a mouseup event.

Mouse.wheel(deltaX, deltaY)

Added in: v1.15
  • deltaX <double> Pixels to scroll horizontally.#
  • deltaY <double> Pixels to scroll vertically.#
  • returns: <void>#

Dispatches a wheel event.

note

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