1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Mouse - Low-level mouse control
//
// See: https://playwright.dev/docs/api/class-mouse
use crate::error::Result;
use crate::protocol::page::Page;
/// Mouse provides low-level mouse control.
///
/// Coordinates are in main-frame CSS pixels relative to the viewport's top-left corner.
///
/// See: <https://playwright.dev/docs/api/class-mouse>
#[derive(Clone)]
pub struct Mouse {
page: Page,
}
impl Mouse {
/// Creates a new Mouse instance for the given page
pub(crate) fn new(page: Page) -> Self {
Self { page }
}
/// Dispatches a `mousemove` event.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-move>
pub async fn move_to(
&self,
x: i32,
y: i32,
options: Option<crate::protocol::MouseOptions>,
) -> Result<()> {
self.page.mouse_move(x, y, options).await
}
/// Combines `move()`, `down()`, and `up()` actions.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-click>
pub async fn click(
&self,
x: i32,
y: i32,
options: Option<crate::protocol::MouseOptions>,
) -> Result<()> {
self.page.mouse_click(x, y, options).await
}
/// Shortcut performing `move()`, `down()`, `up()`, `down()`, and `up()` sequentially.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-dblclick>
pub async fn dblclick(
&self,
x: i32,
y: i32,
options: Option<crate::protocol::MouseOptions>,
) -> Result<()> {
self.page.mouse_dblclick(x, y, options).await
}
/// Dispatches a `mousedown` event.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-down>
pub async fn down(&self, options: Option<crate::protocol::MouseOptions>) -> Result<()> {
self.page.mouse_down(options).await
}
/// Dispatches a `mouseup` event.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-up>
pub async fn up(&self, options: Option<crate::protocol::MouseOptions>) -> Result<()> {
self.page.mouse_up(options).await
}
/// Dispatches a `wheel` event for manual page scrolling.
///
/// See: <https://playwright.dev/docs/api/class-mouse#mouse-wheel>
pub async fn wheel(&self, delta_x: i32, delta_y: i32) -> Result<()> {
self.page.mouse_wheel(delta_x, delta_y).await
}
}