2021-01-07 11:46:05 -08:00
# class: Mouse
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
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 [`property: Page.mouse` ].
```js
// Using ‘ page.mouse’ to trace a 100x100 square.
await page.mouse.move(0, 0);
await page.mouse.down();
await page.mouse.move(0, 100);
await page.mouse.move(100, 100);
await page.mouse.move(100, 0);
await page.mouse.move(0, 0);
await page.mouse.up();
```
2021-02-25 22:03:39 -08:00
```java
// 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();
```
2021-01-14 07:48:56 -08:00
```python async
# using ‘ page.mouse’ to trace a 100x100 square.
await page.mouse.move(0, 0)
await page.mouse.down()
await page.mouse.move(0, 100)
await page.mouse.move(100, 100)
await page.mouse.move(100, 0)
await page.mouse.move(0, 0)
await page.mouse.up()
```
```python sync
# 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()
```
2021-03-04 19:03:51 +01:00
```csharp
await Page.Mouse.MoveAsync(0, 0);
await Page.Mouse.DownAsync();
await Page.Mouse.MoveAsync(0, 100);
await Page.Mouse.MoveAsync(100, 100);
await Page.Mouse.MoveAsync(100, 0);
await Page.Mouse.MoveAsync(0, 0);
await Page.Mouse.UpAsync();
```
2022-11-21 09:30:32 -08:00
2021-01-07 11:46:05 -08:00
## async method: Mouse.click
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
Shortcut for [`method: Mouse.move` ], [`method: Mouse.down` ], [`method: Mouse.up` ].
### param: Mouse.click.x
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `x` < [float]>
2024-07-09 12:52:51 +02:00
X coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### param: Mouse.click.y
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `y` < [float]>
2024-07-09 12:52:51 +02:00
Y coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### option: Mouse.click.button = %%-input-button-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
### option: Mouse.click.clickCount = %%-input-click-count-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
### option: Mouse.click.delay = %%-input-down-up-delay-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
## async method: Mouse.dblclick
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-05-19 16:29:35 -07:00
* langs:
- alias-csharp: DblClickAsync
2021-01-07 11:46:05 -08:00
Shortcut for [`method: Mouse.move` ], [`method: Mouse.down` ], [`method: Mouse.up` ], [`method: Mouse.down` ] and
[`method: Mouse.up` ].
### param: Mouse.dblclick.x
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `x` < [float]>
2024-07-09 12:52:51 +02:00
X coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### param: Mouse.dblclick.y
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `y` < [float]>
2024-07-09 12:52:51 +02:00
Y coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### option: Mouse.dblclick.button = %%-input-button-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
### option: Mouse.dblclick.delay = %%-input-down-up-delay-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
## async method: Mouse.down
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
Dispatches a `mousedown` event.
### option: Mouse.down.button = %%-input-button-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
### option: Mouse.down.clickCount = %%-input-click-count-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
## async method: Mouse.move
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
Dispatches a `mousemove` event.
### param: Mouse.move.x
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `x` < [float]>
2024-07-09 12:52:51 +02:00
X coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### param: Mouse.move.y
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `y` < [float]>
2024-07-09 12:52:51 +02:00
Y coordinate relative to the main frame's viewport in CSS pixels.
2021-01-07 11:46:05 -08:00
### option: Mouse.move.steps
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `steps` < [int]>
2022-04-06 19:02:10 -07:00
Defaults to 1. Sends intermediate `mousemove` events.
2021-01-07 11:46:05 -08:00
## async method: Mouse.up
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
Dispatches a `mouseup` event.
### option: Mouse.up.button = %%-input-button-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
### option: Mouse.up.clickCount = %%-input-click-count-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-09-14 15:22:52 -04:00
## async method: Mouse.wheel
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-14 15:22:52 -04:00
2024-05-08 21:04:05 -07:00
Dispatches a `wheel` event. This method is usually used to manually scroll the page. See [scrolling ](../input.md#scrolling ) for alternative ways to scroll.
2021-09-14 15:22:52 -04:00
:::note
Wheel events may cause scrolling if they are not handled, and this method does not
wait for the scrolling to finish before returning.
:::
### param: Mouse.wheel.deltaX
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-14 15:22:52 -04:00
- `deltaX` < [float]>
Pixels to scroll horizontally.
### param: Mouse.wheel.deltaY
2022-07-05 16:24:50 -08:00
* since: v1.15
2021-09-14 15:22:52 -04:00
- `deltaY` < [float]>
Pixels to scroll vertically.