browser_commander/puppeteer/api/locator.rs
1// @generated by scripts/generate-puppeteer-bindings.mjs from
2// rust/protocol/puppeteer/api.json. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]
5
6use serde_json::Value;
7
8use super::*;
9use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};
10
11remote_type!(
12 /// Puppeteer's `Locator` (puppeteer-core 25.10.0), a remote object
13 /// served by `browser-commander serve --stdio`.
14 ///
15 /// Extends [`EventEmitter`]; the inherited methods are repeated here.
16 Locator
17);
18
19impl Locator {
20 /// `EventEmitter.on`
21 ///
22 /// ```text
23 /// on<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
24 /// ```
25 pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
26 self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
27 }
28
29 /// `EventEmitter.off`
30 ///
31 /// ```text
32 /// off<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler?: Handler<EventsWithWildcard<Events>[Key]>): this
33 /// ```
34 pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<Locator, BridgeError> {
35 self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
36 }
37
38 /// `EventEmitter.emit`
39 ///
40 /// ```text
41 /// emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<Events>[Key]): boolean
42 /// ```
43 pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
44 self.remote.call("emit", vec![Some(type_), Some(event)]).await
45 }
46
47 /// `EventEmitter.once`
48 ///
49 /// ```text
50 /// once<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
51 /// ```
52 pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
53 self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
54 }
55
56 /// `EventEmitter.listenerCount`
57 ///
58 /// ```text
59 /// listenerCount(type: keyof EventsWithWildcard<Events>): number
60 /// ```
61 pub async fn listener_count(&self, type_: Value) -> Result<f64, BridgeError> {
62 self.remote.call("listenerCount", vec![Some(type_)]).await
63 }
64
65 /// `EventEmitter.removeAllListeners`
66 ///
67 /// ```text
68 /// removeAllListeners(type?: keyof EventsWithWildcard<Events>): this
69 /// ```
70 pub async fn remove_all_listeners(&self, type_: Option<Value>) -> Result<Locator, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 /// `Locator.timeout`
75 ///
76 /// ```text
77 /// get timeout(): number
78 /// ```
79 pub async fn timeout(&self) -> Result<f64, BridgeError> {
80 self.remote.get("timeout").await
81 }
82
83 /// `Locator.setTimeout`
84 ///
85 /// ```text
86 /// setTimeout(timeout: number): Locator<T>
87 /// ```
88 pub async fn set_timeout(&self, timeout: f64) -> Result<Locator, BridgeError> {
89 self.remote.call("setTimeout", vec![Some(Value::from(timeout))]).await
90 }
91
92 /// `Locator.setVisibility`
93 ///
94 /// ```text
95 /// setVisibility<NodeType extends Node>(this: Locator<NodeType>, visibility: VisibilityOption): Locator<NodeType>
96 /// ```
97 pub async fn set_visibility(&self, this: &Locator, visibility: Option<&str>) -> Result<Locator, BridgeError> {
98 self.remote.call("setVisibility", vec![Some(this.remote().to_wire()), Some(visibility.map(|x| Value::from(x)).unwrap_or(Value::Null))]).await
99 }
100
101 /// `Locator.setWaitForEnabled`
102 ///
103 /// ```text
104 /// setWaitForEnabled<NodeType extends Node>(this: Locator<NodeType>, value: boolean): Locator<NodeType>
105 /// ```
106 pub async fn set_wait_for_enabled(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
107 self.remote.call("setWaitForEnabled", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
108 }
109
110 /// `Locator.setEnsureElementIsInTheViewport`
111 ///
112 /// ```text
113 /// setEnsureElementIsInTheViewport<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>
114 /// ```
115 pub async fn set_ensure_element_is_in_the_viewport(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
116 self.remote.call("setEnsureElementIsInTheViewport", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
117 }
118
119 /// `Locator.setWaitForStableBoundingBox`
120 ///
121 /// ```text
122 /// setWaitForStableBoundingBox<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>
123 /// ```
124 pub async fn set_wait_for_stable_bounding_box(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
125 self.remote.call("setWaitForStableBoundingBox", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
126 }
127
128 /// `Locator.clone`
129 ///
130 /// ```text
131 /// clone(): Locator<T>
132 /// ```
133 pub async fn js_clone(&self) -> Result<Locator, BridgeError> {
134 self.remote.call("clone", vec![]).await
135 }
136
137 /// `Locator.waitHandle`
138 ///
139 /// ```text
140 /// waitHandle(options?: Readonly<ActionOptions>): Promise<HandleFor<T>>
141 /// ```
142 pub async fn wait_handle(&self, options: Option<Value>) -> Result<JSHandle, BridgeError> {
143 self.remote.call("waitHandle", vec![options]).await
144 }
145
146 /// `Locator.wait`
147 ///
148 /// ```text
149 /// wait(options?: Readonly<ActionOptions>): Promise<T>
150 /// ```
151 pub async fn wait(&self, options: Option<Value>) -> Result<Value, BridgeError> {
152 self.remote.call("wait", vec![options]).await
153 }
154
155 /// `Locator.map`
156 ///
157 /// ```text
158 /// map<To>(mapper: Mapper<T, To>): Locator<To>
159 /// ```
160 pub async fn map(&self, mapper: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
161 self.remote.call("map", vec![Some(mapper.into().to_wire())]).await
162 }
163
164 /// `Locator.filter`
165 ///
166 /// ```text
167 /// filter<S extends T>(predicate: Predicate<T, S>): Locator<S>
168 /// ```
169 pub async fn filter(&self, predicate: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
170 self.remote.call("filter", vec![Some(predicate.into().to_wire())]).await
171 }
172
173 /// `Locator.click`
174 ///
175 /// ```text
176 /// click<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorClickOptions>): Promise<void>
177 /// ```
178 pub async fn click(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
179 self.remote.call("click", vec![Some(this.remote().to_wire()), options]).await
180 }
181
182 /// `Locator.fill`
183 ///
184 /// ```text
185 /// fill<ElementType extends Element>(this: Locator<ElementType>, value: string | boolean, options?: Readonly<LocatorFillOptions>): Promise<void>
186 /// ```
187 pub async fn fill(&self, this: &Locator, value: Value, options: Option<Value>) -> Result<(), BridgeError> {
188 self.remote.call("fill", vec![Some(this.remote().to_wire()), Some(value), options]).await
189 }
190
191 /// `Locator.hover`
192 ///
193 /// ```text
194 /// hover<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<ActionOptions>): Promise<void>
195 /// ```
196 pub async fn hover(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
197 self.remote.call("hover", vec![Some(this.remote().to_wire()), options]).await
198 }
199
200 /// `Locator.scroll`
201 ///
202 /// ```text
203 /// scroll<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorScrollOptions>): Promise<void>
204 /// ```
205 pub async fn scroll(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
206 self.remote.call("scroll", vec![Some(this.remote().to_wire()), options]).await
207 }
208}