Skip to content

Lupa API Reference / commands / Mouse

Class: Mouse

Defined in: src/commands/mouse.ts:131

Controls mouse movements and button actions. It uses RPC calls to interact with Playwright's Mouse object.

Use

when

  • Simulating precise coordinate-based mouse interactions such as drawing, custom dragging, or triggering pointer events at specific offsets.

Dont

use when

  • Interacting with standard DOM elements. Instead, use locators (e.g., query().click(), query().hover()) which automatically handle actionability checks, scrolling, and are much less brittle.

Constructors

Constructor

new Mouse(): Mouse

Returns

Mouse

Methods

click()

click(point, options?): Promise<void>

Defined in: src/commands/mouse.ts:247

Clicks at the specified coordinates.

Parameters

point

Point

options?

MouseClickOptions

Returns

Promise<void>

Example

Left-clicking at (100, 150)

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.click({ x: 100, y: 150 })

dblclick()

dblclick(point, options?): Promise<void>

Defined in: src/commands/mouse.ts:261

Double-clicks at the specified coordinates.

Parameters

point

Point

options?

MouseDblClickOptions

Returns

Promise<void>

Example

Double-clicking at (200, 250)

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.dblclick({ x: 200, y: 250 })

down()

down(options?): Promise<void>

Defined in: src/commands/mouse.ts:219

Presses a mouse button down.

Parameters

options?

MouseDownOptions

Returns

Promise<void>

Example

Pressing left mouse button down

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.down()

move()

Call Signature

move(point, options?): Promise<void>

Defined in: src/commands/mouse.ts:182

Moves the mouse to a specific point, or from a starting point to a destination.

Parameters
point

Point

options?

MouseMoveOptions

Returns

Promise<void>

Examples

Move mouse to coordinate (100, 200)

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.move({ x: 100, y: 200 }, { steps: 5 })

Drag from (100, 100) to (200, 200) holding the left mouse button

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.move({ x: 100, y: 100 }, { x: 200, y: 200 }, { button: 'left', steps: 10 })

Call Signature

move(from, to, options?): Promise<void>

Defined in: src/commands/mouse.ts:183

Moves the mouse to a specific point, or from a starting point to a destination.

Parameters
from

Point

to

Point

options?

MouseMoveOptions

Returns

Promise<void>

Examples

Move mouse to coordinate (100, 200)

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.move({ x: 100, y: 200 }, { steps: 5 })

Drag from (100, 100) to (200, 200) holding the left mouse button

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.move({ x: 100, y: 100 }, { x: 200, y: 200 }, { button: 'left', steps: 10 })

press()

press(point, options?): Promise<void>

Defined in: src/commands/mouse.ts:276

Presses on specific coordinates, optionally holding down a keyboard modifier key and/or holding down the button for a specific duration.

Parameters

point

Point

options?

MousePressOptions

Returns

Promise<void>

Example

Pressing and holding left click at (150, 150) for 500ms

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.press({ x: 150, y: 150 }, { button: 'left', delay: 500 })

reset()

reset(): Promise<void>

Defined in: src/commands/mouse.ts:144

Resets the mouse position to (0, 0) and releases all pressed mouse buttons.

Returns

Promise<void>

A promise that resolves when the reset action is completed.

Example

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.reset()

setPosition()

setPosition(point): Promise<void>

Defined in: src/commands/mouse.ts:161

Immediately sets the mouse position to the specified coordinates without emitting steps or transition events.

Parameters

point

Point

Point object specifying coordinates.

Returns

Promise<void>

A promise that resolves when the mouse position is set.

Example

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.setPosition({ x: 100, y: 150 })

up()

up(options?): Promise<void>

Defined in: src/commands/mouse.ts:233

Releases a mouse button.

Parameters

options?

MouseUpOptions

Returns

Promise<void>

Example

Releasing left mouse button

typescript
import { mouse } from '@pawel-up/lupa/commands'

await mouse.up()