playwright-ruby-client 0.8.1 → 1.14.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/documentation/docs/api/accessibility.md +51 -1
- data/documentation/docs/api/browser_context.md +28 -0
- data/documentation/docs/api/download.md +97 -0
- data/documentation/docs/api/element_handle.md +28 -3
- data/documentation/docs/api/experimental/android.md +15 -2
- data/documentation/docs/api/frame.md +116 -114
- data/documentation/docs/api/locator.md +650 -0
- data/documentation/docs/api/mouse.md +3 -4
- data/documentation/docs/api/page.md +109 -19
- data/documentation/docs/api/request.md +15 -19
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +13 -12
- data/documentation/docs/api/worker.md +37 -0
- data/documentation/docs/article/guides/inspector.md +31 -0
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
- data/documentation/docs/article/guides/semi_automation.md +1 -1
- data/documentation/docs/include/api_coverage.md +70 -14
- data/lib/playwright.rb +0 -1
- data/lib/playwright/accessibility_impl.rb +50 -0
- data/lib/playwright/channel_owners/browser_context.rb +70 -0
- data/lib/playwright/channel_owners/frame.rb +79 -33
- data/lib/playwright/channel_owners/page.rb +133 -42
- data/lib/playwright/channel_owners/request.rb +8 -8
- data/lib/playwright/channel_owners/worker.rb +23 -0
- data/lib/playwright/{download.rb → download_impl.rb} +1 -1
- data/lib/playwright/javascript/expression.rb +5 -4
- data/lib/playwright/locator_impl.rb +314 -0
- data/lib/playwright/timeout_settings.rb +4 -4
- data/lib/playwright/touchscreen_impl.rb +7 -0
- data/lib/playwright/tracing_impl.rb +9 -8
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/accessibility.rb +1 -1
- data/lib/playwright_api/android.rb +21 -8
- data/lib/playwright_api/android_device.rb +6 -6
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +16 -11
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/download.rb +70 -0
- data/lib/playwright_api/element_handle.rb +34 -20
- data/lib/playwright_api/frame.rb +85 -53
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +509 -0
- data/lib/playwright_api/page.rb +91 -57
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/touchscreen.rb +1 -1
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +16 -6
- metadata +13 -6
@@ -88,12 +88,6 @@ module Playwright
|
|
88
88
|
wrap_impl(@impl.to_s)
|
89
89
|
end
|
90
90
|
|
91
|
-
# -- inherited from EventEmitter --
|
92
|
-
# @nodoc
|
93
|
-
def off(event, callback)
|
94
|
-
event_emitter_proxy.off(event, callback)
|
95
|
-
end
|
96
|
-
|
97
91
|
# -- inherited from EventEmitter --
|
98
92
|
# @nodoc
|
99
93
|
def once(event, callback)
|
@@ -106,6 +100,12 @@ module Playwright
|
|
106
100
|
event_emitter_proxy.on(event, callback)
|
107
101
|
end
|
108
102
|
|
103
|
+
# -- inherited from EventEmitter --
|
104
|
+
# @nodoc
|
105
|
+
def off(event, callback)
|
106
|
+
event_emitter_proxy.off(event, callback)
|
107
|
+
end
|
108
|
+
|
109
109
|
private def event_emitter_proxy
|
110
110
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
111
111
|
end
|
@@ -0,0 +1,509 @@
|
|
1
|
+
module Playwright
|
2
|
+
# Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
|
3
|
+
# given moment. Locator can be created with the [`method: Page.locator`] method.
|
4
|
+
#
|
5
|
+
# ```python sync
|
6
|
+
# locator = page.locator("text=Submit")
|
7
|
+
# locator.click()
|
8
|
+
# ```
|
9
|
+
#
|
10
|
+
# The difference between the Locator and `ElementHandle` is that the latter points to a particular element, while Locator
|
11
|
+
# captures the logic of how to retrieve that element.
|
12
|
+
#
|
13
|
+
# In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
|
14
|
+
# React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
|
15
|
+
# unexpected behaviors.
|
16
|
+
#
|
17
|
+
# ```python sync
|
18
|
+
# handle = page.query_selector("text=Submit")
|
19
|
+
# handle.hover()
|
20
|
+
# handle.click()
|
21
|
+
# ```
|
22
|
+
#
|
23
|
+
# With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
|
24
|
+
# in the snippet below, underlying DOM element is going to be located twice.
|
25
|
+
#
|
26
|
+
# ```python sync
|
27
|
+
# locator = page.locator("text=Submit")
|
28
|
+
# locator.hover()
|
29
|
+
# locator.click()
|
30
|
+
# ```
|
31
|
+
class Locator < PlaywrightApi
|
32
|
+
|
33
|
+
# Returns an array of `node.innerText` values for all matching nodes.
|
34
|
+
def all_inner_texts
|
35
|
+
wrap_impl(@impl.all_inner_texts)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns an array of `node.textContent` values for all matching nodes.
|
39
|
+
def all_text_contents
|
40
|
+
wrap_impl(@impl.all_text_contents)
|
41
|
+
end
|
42
|
+
|
43
|
+
# This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
|
44
|
+
# calculated relative to the main frame viewport - which is usually the same as the browser window.
|
45
|
+
#
|
46
|
+
# Scrolling affects the returned bonding box, similarly to
|
47
|
+
# [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
|
48
|
+
# means `x` and/or `y` may be negative.
|
49
|
+
#
|
50
|
+
# Elements from child frames return the bounding box relative to the main frame, unlike the
|
51
|
+
# [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
|
52
|
+
#
|
53
|
+
# Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
54
|
+
# snippet should click the center of the element.
|
55
|
+
#
|
56
|
+
# ```python sync
|
57
|
+
# box = element.bounding_box()
|
58
|
+
# page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
|
59
|
+
# ```
|
60
|
+
def bounding_box(timeout: nil)
|
61
|
+
wrap_impl(@impl.bounding_box(timeout: unwrap_impl(timeout)))
|
62
|
+
end
|
63
|
+
|
64
|
+
# This method checks the element by performing the following steps:
|
65
|
+
# 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked,
|
66
|
+
# this method returns immediately.
|
67
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
68
|
+
# 1. Scroll the element into view if needed.
|
69
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
70
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
71
|
+
# 1. Ensure that the element is now checked. If not, this method throws.
|
72
|
+
#
|
73
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
74
|
+
#
|
75
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
76
|
+
# zero timeout disables this.
|
77
|
+
def check(
|
78
|
+
force: nil,
|
79
|
+
noWaitAfter: nil,
|
80
|
+
position: nil,
|
81
|
+
timeout: nil,
|
82
|
+
trial: nil)
|
83
|
+
wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
84
|
+
end
|
85
|
+
|
86
|
+
# This method clicks the element by performing the following steps:
|
87
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
88
|
+
# 1. Scroll the element into view if needed.
|
89
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
|
90
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
91
|
+
#
|
92
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
93
|
+
#
|
94
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
95
|
+
# zero timeout disables this.
|
96
|
+
def click(
|
97
|
+
button: nil,
|
98
|
+
clickCount: nil,
|
99
|
+
delay: nil,
|
100
|
+
force: nil,
|
101
|
+
modifiers: nil,
|
102
|
+
noWaitAfter: nil,
|
103
|
+
position: nil,
|
104
|
+
timeout: nil,
|
105
|
+
trial: nil)
|
106
|
+
wrap_impl(@impl.click(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
107
|
+
end
|
108
|
+
|
109
|
+
# Returns the number of elements matching given selector.
|
110
|
+
def count
|
111
|
+
wrap_impl(@impl.count)
|
112
|
+
end
|
113
|
+
|
114
|
+
# This method double clicks the element by performing the following steps:
|
115
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
116
|
+
# 1. Scroll the element into view if needed.
|
117
|
+
# 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
|
118
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
|
119
|
+
# first click of the `dblclick()` triggers a navigation event, this method will throw.
|
120
|
+
#
|
121
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
122
|
+
#
|
123
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
124
|
+
# zero timeout disables this.
|
125
|
+
#
|
126
|
+
# > NOTE: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
127
|
+
def dblclick(
|
128
|
+
button: nil,
|
129
|
+
delay: nil,
|
130
|
+
force: nil,
|
131
|
+
modifiers: nil,
|
132
|
+
noWaitAfter: nil,
|
133
|
+
position: nil,
|
134
|
+
timeout: nil,
|
135
|
+
trial: nil)
|
136
|
+
wrap_impl(@impl.dblclick(button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
137
|
+
end
|
138
|
+
|
139
|
+
# The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
|
140
|
+
# `click` is dispatched. This is equivalent to calling
|
141
|
+
# [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
142
|
+
#
|
143
|
+
# ```python sync
|
144
|
+
# element.dispatch_event("click")
|
145
|
+
# ```
|
146
|
+
#
|
147
|
+
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
148
|
+
# and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
|
149
|
+
#
|
150
|
+
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
|
151
|
+
# - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
|
152
|
+
# - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
|
153
|
+
# - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
|
154
|
+
# - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
|
155
|
+
# - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
|
156
|
+
# - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
|
157
|
+
# - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
|
158
|
+
#
|
159
|
+
# You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
|
160
|
+
#
|
161
|
+
# ```python sync
|
162
|
+
# # note you can only create data_transfer in chromium and firefox
|
163
|
+
# data_transfer = page.evaluate_handle("new DataTransfer()")
|
164
|
+
# element.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
|
165
|
+
# ```
|
166
|
+
def dispatch_event(type, eventInit: nil, timeout: nil)
|
167
|
+
wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
|
168
|
+
end
|
169
|
+
|
170
|
+
# Resolves given locator to the first matching DOM element. If no elements matching the query are visible, waits for them
|
171
|
+
# up to a given timeout. If multiple elements match the selector, throws.
|
172
|
+
def element_handle(timeout: nil)
|
173
|
+
wrap_impl(@impl.element_handle(timeout: unwrap_impl(timeout)))
|
174
|
+
end
|
175
|
+
|
176
|
+
# Resolves given locator to all matching DOM elements.
|
177
|
+
def element_handles
|
178
|
+
wrap_impl(@impl.element_handles)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the return value of `expression`.
|
182
|
+
#
|
183
|
+
# This method passes this handle as the first argument to `expression`.
|
184
|
+
#
|
185
|
+
# If `expression` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its value.
|
186
|
+
#
|
187
|
+
# Examples:
|
188
|
+
#
|
189
|
+
# ```python sync
|
190
|
+
# tweets = page.locator(".tweet .retweets")
|
191
|
+
# assert tweets.evaluate("node => node.innerText") == "10 retweets"
|
192
|
+
# ```
|
193
|
+
def evaluate(expression, arg: nil, timeout: nil)
|
194
|
+
wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
|
195
|
+
end
|
196
|
+
|
197
|
+
# The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
|
198
|
+
# to `expression`. Returns the result of `expression` invocation.
|
199
|
+
#
|
200
|
+
# If `expression` returns a [Promise], then [`method: Locator.evaluateAll`] would wait for the promise to resolve and
|
201
|
+
# return its value.
|
202
|
+
#
|
203
|
+
# Examples:
|
204
|
+
#
|
205
|
+
# ```python sync
|
206
|
+
# elements = page.locator("div")
|
207
|
+
# div_counts = elements("(divs, min) => divs.length >= min", 10)
|
208
|
+
# ```
|
209
|
+
def evaluate_all(expression, arg: nil)
|
210
|
+
wrap_impl(@impl.evaluate_all(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
211
|
+
end
|
212
|
+
|
213
|
+
# Returns the return value of `expression` as a `JSHandle`.
|
214
|
+
#
|
215
|
+
# This method passes this handle as the first argument to `expression`.
|
216
|
+
#
|
217
|
+
# The only difference between [`method: Locator.evaluate`] and [`method: Locator.evaluateHandle`] is that
|
218
|
+
# [`method: Locator.evaluateHandle`] returns `JSHandle`.
|
219
|
+
#
|
220
|
+
# If the function passed to the [`method: Locator.evaluateHandle`] returns a [Promise], then
|
221
|
+
# [`method: Locator.evaluateHandle`] would wait for the promise to resolve and return its value.
|
222
|
+
#
|
223
|
+
# See [`method: Page.evaluateHandle`] for more details.
|
224
|
+
def evaluate_handle(expression, arg: nil, timeout: nil)
|
225
|
+
wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
|
226
|
+
end
|
227
|
+
|
228
|
+
# This method waits for [actionability](./actionability.md) checks, focuses the element, fills it and triggers an `input`
|
229
|
+
# event after filling. Note that you can pass an empty string to clear the input field.
|
230
|
+
#
|
231
|
+
# If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
|
232
|
+
# However, if the element is inside the `<label>` element that has an associated
|
233
|
+
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
|
234
|
+
# instead.
|
235
|
+
#
|
236
|
+
# To send fine-grained keyboard events, use [`method: Locator.type`].
|
237
|
+
def fill(value, force: nil, noWaitAfter: nil, timeout: nil)
|
238
|
+
wrap_impl(@impl.fill(unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
239
|
+
end
|
240
|
+
|
241
|
+
# Returns locator to the first matching element.
|
242
|
+
def first
|
243
|
+
wrap_impl(@impl.first)
|
244
|
+
end
|
245
|
+
|
246
|
+
# Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element.
|
247
|
+
def focus(timeout: nil)
|
248
|
+
wrap_impl(@impl.focus(timeout: unwrap_impl(timeout)))
|
249
|
+
end
|
250
|
+
|
251
|
+
# Returns element attribute value.
|
252
|
+
def get_attribute(name, timeout: nil)
|
253
|
+
wrap_impl(@impl.get_attribute(unwrap_impl(name), timeout: unwrap_impl(timeout)))
|
254
|
+
end
|
255
|
+
|
256
|
+
# This method hovers over the element by performing the following steps:
|
257
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
258
|
+
# 1. Scroll the element into view if needed.
|
259
|
+
# 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
|
260
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
261
|
+
#
|
262
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
263
|
+
#
|
264
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
265
|
+
# zero timeout disables this.
|
266
|
+
def hover(
|
267
|
+
force: nil,
|
268
|
+
modifiers: nil,
|
269
|
+
position: nil,
|
270
|
+
timeout: nil,
|
271
|
+
trial: nil)
|
272
|
+
wrap_impl(@impl.hover(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns the `element.innerHTML`.
|
276
|
+
def inner_html(timeout: nil)
|
277
|
+
wrap_impl(@impl.inner_html(timeout: unwrap_impl(timeout)))
|
278
|
+
end
|
279
|
+
|
280
|
+
# Returns the `element.innerText`.
|
281
|
+
def inner_text(timeout: nil)
|
282
|
+
wrap_impl(@impl.inner_text(timeout: unwrap_impl(timeout)))
|
283
|
+
end
|
284
|
+
|
285
|
+
# Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
|
286
|
+
def input_value(timeout: nil)
|
287
|
+
wrap_impl(@impl.input_value(timeout: unwrap_impl(timeout)))
|
288
|
+
end
|
289
|
+
|
290
|
+
# Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
291
|
+
def checked?(timeout: nil)
|
292
|
+
wrap_impl(@impl.checked?(timeout: unwrap_impl(timeout)))
|
293
|
+
end
|
294
|
+
|
295
|
+
# Returns whether the element is disabled, the opposite of [enabled](./actionability.md#enabled).
|
296
|
+
def disabled?(timeout: nil)
|
297
|
+
wrap_impl(@impl.disabled?(timeout: unwrap_impl(timeout)))
|
298
|
+
end
|
299
|
+
|
300
|
+
# Returns whether the element is [editable](./actionability.md#editable).
|
301
|
+
def editable?(timeout: nil)
|
302
|
+
wrap_impl(@impl.editable?(timeout: unwrap_impl(timeout)))
|
303
|
+
end
|
304
|
+
|
305
|
+
# Returns whether the element is [enabled](./actionability.md#enabled).
|
306
|
+
def enabled?(timeout: nil)
|
307
|
+
wrap_impl(@impl.enabled?(timeout: unwrap_impl(timeout)))
|
308
|
+
end
|
309
|
+
|
310
|
+
# Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
|
311
|
+
def hidden?(timeout: nil)
|
312
|
+
wrap_impl(@impl.hidden?(timeout: unwrap_impl(timeout)))
|
313
|
+
end
|
314
|
+
|
315
|
+
# Returns whether the element is [visible](./actionability.md#visible).
|
316
|
+
def visible?(timeout: nil)
|
317
|
+
wrap_impl(@impl.visible?(timeout: unwrap_impl(timeout)))
|
318
|
+
end
|
319
|
+
|
320
|
+
# Returns locator to the last matching element.
|
321
|
+
def last
|
322
|
+
wrap_impl(@impl.last)
|
323
|
+
end
|
324
|
+
|
325
|
+
# The method finds an element matching the specified selector in the `Locator`'s subtree. See
|
326
|
+
# [Working with selectors](./selectors.md) for more details.
|
327
|
+
def locator(selector)
|
328
|
+
wrap_impl(@impl.locator(unwrap_impl(selector)))
|
329
|
+
end
|
330
|
+
|
331
|
+
# Returns locator to the n-th matching element.
|
332
|
+
def nth(index)
|
333
|
+
wrap_impl(@impl.nth(unwrap_impl(index)))
|
334
|
+
end
|
335
|
+
|
336
|
+
# Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
337
|
+
#
|
338
|
+
# `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
339
|
+
# value or a single character to generate the text for. A superset of the `key` values can be found
|
340
|
+
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
341
|
+
#
|
342
|
+
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
343
|
+
# `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
344
|
+
#
|
345
|
+
# Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
|
346
|
+
#
|
347
|
+
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
348
|
+
#
|
349
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
|
350
|
+
# texts.
|
351
|
+
#
|
352
|
+
# Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
|
353
|
+
# modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
354
|
+
def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
|
355
|
+
wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
356
|
+
end
|
357
|
+
|
358
|
+
# Returns the buffer with the captured screenshot.
|
359
|
+
#
|
360
|
+
# This method waits for the [actionability](./actionability.md) checks, then scrolls element into view before taking a
|
361
|
+
# screenshot. If the element is detached from DOM, the method throws an error.
|
362
|
+
def screenshot(
|
363
|
+
omitBackground: nil,
|
364
|
+
path: nil,
|
365
|
+
quality: nil,
|
366
|
+
timeout: nil,
|
367
|
+
type: nil)
|
368
|
+
wrap_impl(@impl.screenshot(omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
|
369
|
+
end
|
370
|
+
|
371
|
+
# This method waits for [actionability](./actionability.md) checks, then tries to scroll element into view, unless it is
|
372
|
+
# completely visible as defined by
|
373
|
+
# [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
|
374
|
+
def scroll_into_view_if_needed(timeout: nil)
|
375
|
+
wrap_impl(@impl.scroll_into_view_if_needed(timeout: unwrap_impl(timeout)))
|
376
|
+
end
|
377
|
+
|
378
|
+
# This method waits for [actionability](./actionability.md) checks, waits until all specified options are present in the
|
379
|
+
# `<select>` element and selects these options.
|
380
|
+
#
|
381
|
+
# If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
|
382
|
+
# `<label>` element that has an associated
|
383
|
+
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
|
384
|
+
#
|
385
|
+
# Returns the array of option values that have been successfully selected.
|
386
|
+
#
|
387
|
+
# Triggers a `change` and `input` event once all the provided options have been selected.
|
388
|
+
#
|
389
|
+
# ```python sync
|
390
|
+
# # single selection matching the value
|
391
|
+
# element.select_option("blue")
|
392
|
+
# # single selection matching both the label
|
393
|
+
# element.select_option(label="blue")
|
394
|
+
# # multiple selection
|
395
|
+
# element.select_option(value=["red", "green", "blue"])
|
396
|
+
# ```
|
397
|
+
#
|
398
|
+
# ```python sync
|
399
|
+
# # single selection matching the value
|
400
|
+
# element.select_option("blue")
|
401
|
+
# # single selection matching both the value and the label
|
402
|
+
# element.select_option(label="blue")
|
403
|
+
# # multiple selection
|
404
|
+
# element.select_option("red", "green", "blue")
|
405
|
+
# # multiple selection for blue, red and second option
|
406
|
+
# element.select_option(value="blue", { index: 2 }, "red")
|
407
|
+
# ```
|
408
|
+
def select_option(
|
409
|
+
element: nil,
|
410
|
+
index: nil,
|
411
|
+
value: nil,
|
412
|
+
label: nil,
|
413
|
+
force: nil,
|
414
|
+
noWaitAfter: nil,
|
415
|
+
timeout: nil)
|
416
|
+
wrap_impl(@impl.select_option(element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
417
|
+
end
|
418
|
+
|
419
|
+
# This method waits for [actionability](./actionability.md) checks, then focuses the element and selects all its text
|
420
|
+
# content.
|
421
|
+
def select_text(force: nil, timeout: nil)
|
422
|
+
wrap_impl(@impl.select_text(force: unwrap_impl(force), timeout: unwrap_impl(timeout)))
|
423
|
+
end
|
424
|
+
|
425
|
+
# This method expects `element` to point to an
|
426
|
+
# [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
427
|
+
#
|
428
|
+
# Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
|
429
|
+
# are resolved relative to the the current working directory. For empty array, clears the selected files.
|
430
|
+
def set_input_files(files, noWaitAfter: nil, timeout: nil)
|
431
|
+
wrap_impl(@impl.set_input_files(unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
432
|
+
end
|
433
|
+
alias_method :input_files=, :set_input_files
|
434
|
+
|
435
|
+
# This method taps the element by performing the following steps:
|
436
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
437
|
+
# 1. Scroll the element into view if needed.
|
438
|
+
# 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
|
439
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
440
|
+
#
|
441
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
442
|
+
#
|
443
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
444
|
+
# zero timeout disables this.
|
445
|
+
#
|
446
|
+
# > NOTE: `element.tap()` requires that the `hasTouch` option of the browser context be set to true.
|
447
|
+
def tap_point(
|
448
|
+
force: nil,
|
449
|
+
modifiers: nil,
|
450
|
+
noWaitAfter: nil,
|
451
|
+
position: nil,
|
452
|
+
timeout: nil,
|
453
|
+
trial: nil)
|
454
|
+
wrap_impl(@impl.tap_point(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
455
|
+
end
|
456
|
+
|
457
|
+
# Returns the `node.textContent`.
|
458
|
+
def text_content(timeout: nil)
|
459
|
+
wrap_impl(@impl.text_content(timeout: unwrap_impl(timeout)))
|
460
|
+
end
|
461
|
+
|
462
|
+
# Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
463
|
+
#
|
464
|
+
# To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
|
465
|
+
#
|
466
|
+
# ```python sync
|
467
|
+
# element.type("hello") # types instantly
|
468
|
+
# element.type("world", delay=100) # types slower, like a user
|
469
|
+
# ```
|
470
|
+
#
|
471
|
+
# An example of typing into a text field and then submitting the form:
|
472
|
+
#
|
473
|
+
# ```python sync
|
474
|
+
# element = page.locator("input")
|
475
|
+
# element.type("some text")
|
476
|
+
# element.press("Enter")
|
477
|
+
# ```
|
478
|
+
def type(text, delay: nil, noWaitAfter: nil, timeout: nil)
|
479
|
+
wrap_impl(@impl.type(unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
480
|
+
end
|
481
|
+
|
482
|
+
# This method checks the element by performing the following steps:
|
483
|
+
# 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
|
484
|
+
# unchecked, this method returns immediately.
|
485
|
+
# 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
|
486
|
+
# 1. Scroll the element into view if needed.
|
487
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
488
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
489
|
+
# 1. Ensure that the element is now unchecked. If not, this method throws.
|
490
|
+
#
|
491
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
492
|
+
#
|
493
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
494
|
+
# zero timeout disables this.
|
495
|
+
def uncheck(
|
496
|
+
force: nil,
|
497
|
+
noWaitAfter: nil,
|
498
|
+
position: nil,
|
499
|
+
timeout: nil,
|
500
|
+
trial: nil)
|
501
|
+
wrap_impl(@impl.uncheck(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
502
|
+
end
|
503
|
+
|
504
|
+
# @nodoc
|
505
|
+
def to_s
|
506
|
+
wrap_impl(@impl.to_s)
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|