playwright-ruby-client 1.28.1 → 1.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/docs/api/accessibility.md +9 -14
- data/documentation/docs/api/api_request_context.md +44 -41
- data/documentation/docs/api/api_response.md +13 -3
- data/documentation/docs/api/browser.md +24 -23
- data/documentation/docs/api/browser_context.md +71 -45
- data/documentation/docs/api/browser_type.md +21 -14
- data/documentation/docs/api/cdp_session.md +3 -5
- data/documentation/docs/api/console_message.md +7 -4
- data/documentation/docs/api/dialog.md +9 -5
- data/documentation/docs/api/download.md +19 -11
- data/documentation/docs/api/element_handle.md +125 -116
- data/documentation/docs/api/experimental/android.md +4 -5
- data/documentation/docs/api/experimental/android_device.md +11 -2
- data/documentation/docs/api/experimental/android_input.md +5 -0
- data/documentation/docs/api/file_chooser.md +6 -3
- data/documentation/docs/api/frame.md +182 -171
- data/documentation/docs/api/frame_locator.md +27 -38
- data/documentation/docs/api/js_handle.md +16 -10
- data/documentation/docs/api/keyboard.md +29 -16
- data/documentation/docs/api/locator.md +189 -140
- data/documentation/docs/api/mouse.md +9 -4
- data/documentation/docs/api/page.md +304 -289
- data/documentation/docs/api/playwright.md +8 -5
- data/documentation/docs/api/request.md +34 -15
- data/documentation/docs/api/response.md +27 -10
- data/documentation/docs/api/route.md +44 -12
- data/documentation/docs/api/selectors.md +5 -3
- data/documentation/docs/api/touchscreen.md +2 -0
- data/documentation/docs/api/tracing.md +11 -11
- data/documentation/docs/api/web_socket.md +9 -4
- data/documentation/docs/api/worker.md +12 -11
- data/documentation/docs/include/api_coverage.md +2 -0
- data/lib/playwright/channel_owners/api_request_context.rb +37 -2
- data/lib/playwright/channel_owners/browser_context.rb +22 -26
- data/lib/playwright/channel_owners/page.rb +35 -25
- data/lib/playwright/channel_owners/route.rb +28 -8
- data/lib/playwright/event_emitter.rb +6 -1
- data/lib/playwright/locator_impl.rb +8 -0
- data/lib/playwright/select_option_values.rb +2 -0
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/accessibility.rb +9 -13
- data/lib/playwright_api/android.rb +8 -6
- data/lib/playwright_api/android_device.rb +32 -7
- data/lib/playwright_api/android_input.rb +5 -0
- data/lib/playwright_api/android_socket.rb +4 -2
- data/lib/playwright_api/android_web_view.rb +5 -2
- data/lib/playwright_api/api_request.rb +6 -3
- data/lib/playwright_api/api_request_context.rb +46 -36
- data/lib/playwright_api/api_response.rb +13 -2
- data/lib/playwright_api/browser.rb +24 -16
- data/lib/playwright_api/browser_context.rb +76 -39
- data/lib/playwright_api/browser_type.rb +23 -13
- data/lib/playwright_api/cdp_session.rb +3 -4
- data/lib/playwright_api/console_message.rb +7 -2
- data/lib/playwright_api/dialog.rb +8 -4
- data/lib/playwright_api/download.rb +19 -9
- data/lib/playwright_api/element_handle.rb +116 -93
- data/lib/playwright_api/file_chooser.rb +6 -1
- data/lib/playwright_api/frame.rb +180 -135
- data/lib/playwright_api/frame_locator.rb +29 -32
- data/lib/playwright_api/js_handle.rb +16 -6
- data/lib/playwright_api/keyboard.rb +29 -14
- data/lib/playwright_api/locator.rb +183 -112
- data/lib/playwright_api/mouse.rb +9 -2
- data/lib/playwright_api/page.rb +301 -253
- data/lib/playwright_api/playwright.rb +11 -4
- data/lib/playwright_api/request.rb +34 -7
- data/lib/playwright_api/response.rb +27 -10
- data/lib/playwright_api/route.rb +44 -11
- data/lib/playwright_api/selectors.rb +6 -1
- data/lib/playwright_api/touchscreen.rb +2 -0
- data/lib/playwright_api/tracing.rb +11 -5
- data/lib/playwright_api/web_socket.rb +9 -4
- data/lib/playwright_api/worker.rb +16 -13
- data/playwright.gemspec +1 -1
- metadata +7 -7
data/lib/playwright_api/page.rb
CHANGED
@@ -44,9 +44,6 @@ module Playwright
|
|
44
44
|
# ```
|
45
45
|
class Page < PlaywrightApi
|
46
46
|
|
47
|
-
# **DEPRECATED** This property is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
|
48
|
-
# need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
|
49
|
-
# integration with Axe.
|
50
47
|
def accessibility # property
|
51
48
|
wrap_impl(@impl.accessibility)
|
52
49
|
end
|
@@ -59,6 +56,7 @@ module Playwright
|
|
59
56
|
wrap_impl(@impl.mouse)
|
60
57
|
end
|
61
58
|
|
59
|
+
#
|
62
60
|
# API testing helper associated with this page. This method returns the same instance as
|
63
61
|
# [`property: BrowserContext.request`] on the page's context. See [`property: BrowserContext.request`] for more details.
|
64
62
|
def request # property
|
@@ -69,14 +67,16 @@ module Playwright
|
|
69
67
|
wrap_impl(@impl.touchscreen)
|
70
68
|
end
|
71
69
|
|
70
|
+
#
|
72
71
|
# Adds a script which would be evaluated in one of the following scenarios:
|
73
72
|
# - Whenever the page is navigated.
|
74
|
-
# - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly
|
75
|
-
# attached frame.
|
73
|
+
# - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
|
76
74
|
#
|
77
75
|
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
78
76
|
# the JavaScript environment, e.g. to seed `Math.random`.
|
79
77
|
#
|
78
|
+
# **Usage**
|
79
|
+
#
|
80
80
|
# An example of overriding `Math.random` before the page loads:
|
81
81
|
#
|
82
82
|
# ```python sync
|
@@ -84,48 +84,44 @@ module Playwright
|
|
84
84
|
# page.add_init_script(path="./preload.js")
|
85
85
|
# ```
|
86
86
|
#
|
87
|
-
#
|
87
|
+
# **NOTE**: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
88
88
|
# [`method: Page.addInitScript`] is not defined.
|
89
89
|
def add_init_script(path: nil, script: nil)
|
90
90
|
wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
|
91
91
|
end
|
92
92
|
|
93
|
+
#
|
93
94
|
# Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
|
94
95
|
# fires or when the script content was injected into frame.
|
95
|
-
#
|
96
|
-
# Shortcut for main frame's [`method: Frame.addScriptTag`].
|
97
96
|
def add_script_tag(content: nil, path: nil, type: nil, url: nil)
|
98
97
|
wrap_impl(@impl.add_script_tag(content: unwrap_impl(content), path: unwrap_impl(path), type: unwrap_impl(type), url: unwrap_impl(url)))
|
99
98
|
end
|
100
99
|
|
100
|
+
#
|
101
101
|
# Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
|
102
102
|
# content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
|
103
|
-
#
|
104
|
-
# Shortcut for main frame's [`method: Frame.addStyleTag`].
|
105
103
|
def add_style_tag(content: nil, path: nil, url: nil)
|
106
104
|
wrap_impl(@impl.add_style_tag(content: unwrap_impl(content), path: unwrap_impl(path), url: unwrap_impl(url)))
|
107
105
|
end
|
108
106
|
|
107
|
+
#
|
109
108
|
# Brings page to front (activates tab).
|
110
109
|
def bring_to_front
|
111
110
|
wrap_impl(@impl.bring_to_front)
|
112
111
|
end
|
113
112
|
|
113
|
+
#
|
114
114
|
# This method checks an element matching `selector` by performing the following steps:
|
115
115
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
116
|
-
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
|
117
|
-
#
|
118
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
119
|
-
# element is detached during the checks, the whole action is retried.
|
116
|
+
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
|
117
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
120
118
|
# 1. Scroll the element into view if needed.
|
121
119
|
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
122
120
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
123
121
|
# 1. Ensure that the element is now checked. If not, this method throws.
|
124
122
|
#
|
125
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
126
|
-
# zero timeout disables this.
|
127
|
-
#
|
128
|
-
# Shortcut for main frame's [`method: Frame.check`].
|
123
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
124
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
129
125
|
def check(
|
130
126
|
selector,
|
131
127
|
force: nil,
|
@@ -137,18 +133,16 @@ module Playwright
|
|
137
133
|
wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
138
134
|
end
|
139
135
|
|
136
|
+
#
|
140
137
|
# This method clicks an element matching `selector` by performing the following steps:
|
141
138
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
142
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
143
|
-
# element is detached during the checks, the whole action is retried.
|
139
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
144
140
|
# 1. Scroll the element into view if needed.
|
145
141
|
# 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
|
146
142
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
147
143
|
#
|
148
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
149
|
-
# zero timeout disables this.
|
150
|
-
#
|
151
|
-
# Shortcut for main frame's [`method: Frame.click`].
|
144
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
145
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
152
146
|
def click(
|
153
147
|
selector,
|
154
148
|
button: nil,
|
@@ -164,42 +158,42 @@ module Playwright
|
|
164
158
|
wrap_impl(@impl.click(unwrap_impl(selector), 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), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
165
159
|
end
|
166
160
|
|
161
|
+
#
|
167
162
|
# If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
|
168
163
|
# `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
|
169
164
|
#
|
170
165
|
# By default, `page.close()` **does not** run `beforeunload` handlers.
|
171
166
|
#
|
172
|
-
#
|
173
|
-
# via [`event: Page.dialog`] event.
|
167
|
+
# **NOTE**: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled
|
168
|
+
# manually via [`event: Page.dialog`] event.
|
174
169
|
def close(runBeforeUnload: nil)
|
175
170
|
wrap_impl(@impl.close(runBeforeUnload: unwrap_impl(runBeforeUnload)))
|
176
171
|
end
|
177
172
|
|
173
|
+
#
|
178
174
|
# Gets the full HTML contents of the page, including the doctype.
|
179
175
|
def content
|
180
176
|
wrap_impl(@impl.content)
|
181
177
|
end
|
182
178
|
|
179
|
+
#
|
183
180
|
# Get the browser context that the page belongs to.
|
184
181
|
def context
|
185
182
|
wrap_impl(@impl.context)
|
186
183
|
end
|
187
184
|
|
185
|
+
#
|
188
186
|
# This method double clicks an element matching `selector` by performing the following steps:
|
189
187
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
190
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
191
|
-
# element is detached during the checks, the whole action is retried.
|
188
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
192
189
|
# 1. Scroll the element into view if needed.
|
193
190
|
# 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
|
194
|
-
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
|
195
|
-
# first click of the `dblclick()` triggers a navigation event, this method will throw.
|
191
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the first click of the `dblclick()` triggers a navigation event, this method will throw.
|
196
192
|
#
|
197
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
198
|
-
# zero timeout disables this.
|
193
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
194
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
199
195
|
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# Shortcut for main frame's [`method: Frame.dblclick`].
|
196
|
+
# **NOTE**: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
203
197
|
def dblclick(
|
204
198
|
selector,
|
205
199
|
button: nil,
|
@@ -214,18 +208,23 @@ module Playwright
|
|
214
208
|
wrap_impl(@impl.dblclick(unwrap_impl(selector), button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
215
209
|
end
|
216
210
|
|
217
|
-
#
|
218
|
-
# `click`
|
211
|
+
#
|
212
|
+
# The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, `click`
|
213
|
+
# is dispatched. This is equivalent to calling
|
219
214
|
# [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
220
215
|
#
|
216
|
+
# **Usage**
|
217
|
+
#
|
221
218
|
# ```python sync
|
222
219
|
# page.dispatch_event("button#submit", "click")
|
223
220
|
# ```
|
224
221
|
#
|
225
|
-
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with
|
226
|
-
# and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
|
222
|
+
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with
|
223
|
+
# `eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
|
224
|
+
# default.
|
227
225
|
#
|
228
|
-
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
|
226
|
+
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
|
227
|
+
# properties:
|
229
228
|
# - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
|
230
229
|
# - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
|
231
230
|
# - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
|
@@ -250,8 +249,12 @@ module Playwright
|
|
250
249
|
wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
251
250
|
end
|
252
251
|
|
253
|
-
#
|
254
|
-
#
|
252
|
+
#
|
253
|
+
# This method drags the source element to the target element.
|
254
|
+
# It will first move to the source element, perform a `mousedown`,
|
255
|
+
# then move to the target element and perform a `mouseup`.
|
256
|
+
#
|
257
|
+
# **Usage**
|
255
258
|
#
|
256
259
|
# ```python sync
|
257
260
|
# page.drag_and_drop("#source", "#target")
|
@@ -276,8 +279,10 @@ module Playwright
|
|
276
279
|
wrap_impl(@impl.drag_and_drop(unwrap_impl(source), unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), sourcePosition: unwrap_impl(sourcePosition), strict: unwrap_impl(strict), targetPosition: unwrap_impl(targetPosition), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
277
280
|
end
|
278
281
|
|
279
|
-
#
|
280
|
-
# feature, using the `colorScheme` argument.
|
282
|
+
#
|
283
|
+
# This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media feature, using the `colorScheme` argument.
|
284
|
+
#
|
285
|
+
# **Usage**
|
281
286
|
#
|
282
287
|
# ```python sync
|
283
288
|
# page.evaluate("matchMedia('screen').matches")
|
@@ -310,30 +315,25 @@ module Playwright
|
|
310
315
|
wrap_impl(@impl.emulate_media(colorScheme: unwrap_impl(colorScheme), forcedColors: unwrap_impl(forcedColors), media: unwrap_impl(media), reducedMotion: unwrap_impl(reducedMotion)))
|
311
316
|
end
|
312
317
|
|
313
|
-
# > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
|
314
|
-
# tests. Use [`method: Locator.evaluate`], other `Locator` helper methods or web-first assertions instead.
|
315
318
|
#
|
316
319
|
# The method finds an element matching the specified selector within the page and passes it as a first argument to
|
317
|
-
# `expression`. If no elements match the selector, the method throws an error. Returns the value of
|
320
|
+
# `expression`. If no elements match the selector, the method throws an error. Returns the value of
|
321
|
+
# `expression`.
|
318
322
|
#
|
319
323
|
# If `expression` returns a [Promise], then [`method: Page.evalOnSelector`] would wait for the promise to resolve and
|
320
324
|
# return its value.
|
321
325
|
#
|
322
|
-
#
|
326
|
+
# **Usage**
|
323
327
|
#
|
324
328
|
# ```python sync
|
325
329
|
# search_value = page.eval_on_selector("#search", "el => el.value")
|
326
330
|
# preload_href = page.eval_on_selector("link[rel=preload]", "el => el.href")
|
327
331
|
# html = page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
|
328
332
|
# ```
|
329
|
-
#
|
330
|
-
# Shortcut for main frame's [`method: Frame.evalOnSelector`].
|
331
333
|
def eval_on_selector(selector, expression, arg: nil, strict: nil)
|
332
334
|
wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg), strict: unwrap_impl(strict)))
|
333
335
|
end
|
334
336
|
|
335
|
-
# > NOTE: In most cases, [`method: Locator.evaluateAll`], other `Locator` helper methods and web-first assertions do a
|
336
|
-
# better job.
|
337
337
|
#
|
338
338
|
# The method finds all elements matching the specified selector within the page and passes an array of matched elements as
|
339
339
|
# a first argument to `expression`. Returns the result of `expression` invocation.
|
@@ -341,7 +341,7 @@ module Playwright
|
|
341
341
|
# If `expression` returns a [Promise], then [`method: Page.evalOnSelectorAll`] would wait for the promise to resolve and
|
342
342
|
# return its value.
|
343
343
|
#
|
344
|
-
#
|
344
|
+
# **Usage**
|
345
345
|
#
|
346
346
|
# ```python sync
|
347
347
|
# div_counts = page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
|
@@ -350,14 +350,17 @@ module Playwright
|
|
350
350
|
wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
|
351
351
|
end
|
352
352
|
|
353
|
+
#
|
353
354
|
# Returns the value of the `expression` invocation.
|
354
355
|
#
|
355
356
|
# If the function passed to the [`method: Page.evaluate`] returns a [Promise], then [`method: Page.evaluate`] would wait
|
356
357
|
# for the promise to resolve and return its value.
|
357
358
|
#
|
358
359
|
# If the function passed to the [`method: Page.evaluate`] returns a non-[Serializable] value, then
|
359
|
-
# [`method: Page.evaluate`] resolves to `undefined`. Playwright also supports transferring some
|
360
|
-
# not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
|
360
|
+
# [`method: Page.evaluate`] resolves to `undefined`. Playwright also supports transferring some
|
361
|
+
# additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
|
362
|
+
#
|
363
|
+
# **Usage**
|
361
364
|
#
|
362
365
|
# Passing argument to `expression`:
|
363
366
|
#
|
@@ -381,19 +384,19 @@ module Playwright
|
|
381
384
|
# html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
|
382
385
|
# body_handle.dispose()
|
383
386
|
# ```
|
384
|
-
#
|
385
|
-
# Shortcut for main frame's [`method: Frame.evaluate`].
|
386
387
|
def evaluate(expression, arg: nil)
|
387
388
|
wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
388
389
|
end
|
389
390
|
|
391
|
+
#
|
390
392
|
# Returns the value of the `expression` invocation as a `JSHandle`.
|
391
393
|
#
|
392
|
-
# The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that
|
393
|
-
#
|
394
|
+
# The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that [`method: Page.evaluateHandle`] returns `JSHandle`.
|
395
|
+
#
|
396
|
+
# If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`] would wait for the
|
397
|
+
# promise to resolve and return its value.
|
394
398
|
#
|
395
|
-
#
|
396
|
-
# would wait for the promise to resolve and return its value.
|
399
|
+
# **Usage**
|
397
400
|
#
|
398
401
|
# ```python sync
|
399
402
|
# a_window_handle = page.evaluate_handle("Promise.resolve(window)")
|
@@ -418,16 +421,19 @@ module Playwright
|
|
418
421
|
wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
419
422
|
end
|
420
423
|
|
421
|
-
# The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
|
422
|
-
# executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
|
423
|
-
# a [Promise], it will be awaited.
|
424
424
|
#
|
425
|
-
# The
|
426
|
-
#
|
425
|
+
# The method adds a function called `name` on the `window` object of every frame in this page. When called, the
|
426
|
+
# function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
|
427
|
+
# If the `callback` returns a [Promise], it will be awaited.
|
428
|
+
#
|
429
|
+
# The first argument of the `callback` function contains information about the caller: `{ browserContext:
|
430
|
+
# BrowserContext, page: Page, frame: Frame }`.
|
427
431
|
#
|
428
432
|
# See [`method: BrowserContext.exposeBinding`] for the context-wide version.
|
429
433
|
#
|
430
|
-
#
|
434
|
+
# **NOTE**: Functions installed via [`method: Page.exposeBinding`] survive navigations.
|
435
|
+
#
|
436
|
+
# **Usage**
|
431
437
|
#
|
432
438
|
# An example of exposing page URL to all frames in a page:
|
433
439
|
#
|
@@ -474,14 +480,17 @@ module Playwright
|
|
474
480
|
wrap_impl(@impl.expose_binding(unwrap_impl(name), unwrap_impl(callback), handle: unwrap_impl(handle)))
|
475
481
|
end
|
476
482
|
|
477
|
-
#
|
478
|
-
#
|
483
|
+
#
|
484
|
+
# The method adds a function called `name` on the `window` object of every frame in the page. When called, the
|
485
|
+
# function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
|
479
486
|
#
|
480
487
|
# If the `callback` returns a [Promise], it will be awaited.
|
481
488
|
#
|
482
489
|
# See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.
|
483
490
|
#
|
484
|
-
#
|
491
|
+
# **NOTE**: Functions installed via [`method: Page.exposeFunction`] survive navigations.
|
492
|
+
#
|
493
|
+
# **Usage**
|
485
494
|
#
|
486
495
|
# An example of adding a `sha256` function to the page:
|
487
496
|
#
|
@@ -518,18 +527,12 @@ module Playwright
|
|
518
527
|
wrap_impl(@impl.expose_function(unwrap_impl(name), unwrap_impl(callback)))
|
519
528
|
end
|
520
529
|
|
521
|
-
# This method waits for an element matching `selector`, waits for [actionability](../actionability.md) checks, focuses the
|
522
|
-
# element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
|
523
|
-
# field.
|
524
530
|
#
|
525
|
-
#
|
526
|
-
# However, if the element is inside the `<label>` element that has an associated
|
527
|
-
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
|
528
|
-
# instead.
|
531
|
+
# This method waits for an element matching `selector`, waits for [actionability](../actionability.md) checks, focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input field.
|
529
532
|
#
|
530
|
-
#
|
533
|
+
# If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled instead.
|
531
534
|
#
|
532
|
-
#
|
535
|
+
# To send fine-grained keyboard events, use [`method: Page.type`].
|
533
536
|
def fill(
|
534
537
|
selector,
|
535
538
|
value,
|
@@ -540,16 +543,18 @@ module Playwright
|
|
540
543
|
wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
541
544
|
end
|
542
545
|
|
543
|
-
# This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
|
544
|
-
# waits until a matching element appears in the DOM.
|
545
546
|
#
|
546
|
-
#
|
547
|
+
# This method fetches an element with `selector` and focuses it. If there's no element matching
|
548
|
+
# `selector`, the method waits until a matching element appears in the DOM.
|
547
549
|
def focus(selector, strict: nil, timeout: nil)
|
548
550
|
wrap_impl(@impl.focus(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
549
551
|
end
|
550
552
|
|
553
|
+
#
|
551
554
|
# Returns frame matching the specified criteria. Either `name` or `url` must be specified.
|
552
555
|
#
|
556
|
+
# **Usage**
|
557
|
+
#
|
553
558
|
# ```py
|
554
559
|
# frame = page.frame(name="frame-name")
|
555
560
|
# ```
|
@@ -561,9 +566,14 @@ module Playwright
|
|
561
566
|
wrap_impl(@impl.frame(name: unwrap_impl(name), url: unwrap_impl(url)))
|
562
567
|
end
|
563
568
|
|
564
|
-
#
|
565
|
-
#
|
566
|
-
#
|
569
|
+
#
|
570
|
+
# When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements
|
571
|
+
# in that iframe.
|
572
|
+
#
|
573
|
+
# **Usage**
|
574
|
+
#
|
575
|
+
# Following snippet locates element with text "Submit" in the iframe with id `my-frame`,
|
576
|
+
# like `<iframe id="my-frame">`:
|
567
577
|
#
|
568
578
|
# ```python sync
|
569
579
|
# locator = page.frame_locator("#my-iframe").get_by_text("Submit")
|
@@ -573,16 +583,19 @@ module Playwright
|
|
573
583
|
wrap_impl(@impl.frame_locator(unwrap_impl(selector)))
|
574
584
|
end
|
575
585
|
|
586
|
+
#
|
576
587
|
# An array of all frames attached to the page.
|
577
588
|
def frames
|
578
589
|
wrap_impl(@impl.frames)
|
579
590
|
end
|
580
591
|
|
592
|
+
#
|
581
593
|
# Returns element attribute value.
|
582
594
|
def get_attribute(selector, name, strict: nil, timeout: nil)
|
583
595
|
wrap_impl(@impl.get_attribute(unwrap_impl(selector), unwrap_impl(name), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
584
596
|
end
|
585
597
|
|
598
|
+
#
|
586
599
|
# Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
587
600
|
#
|
588
601
|
# ```html
|
@@ -592,8 +605,8 @@ module Playwright
|
|
592
605
|
wrap_impl(@impl.get_by_alt_text(unwrap_impl(text), exact: unwrap_impl(exact)))
|
593
606
|
end
|
594
607
|
|
595
|
-
#
|
596
|
-
# label text "Password" in the following DOM:
|
608
|
+
#
|
609
|
+
# Allows locating input elements by the text of the associated label. For example, this method will find the input by label text "Password" in the following DOM:
|
597
610
|
#
|
598
611
|
# ```html
|
599
612
|
# <label for="password-input">Password:</label>
|
@@ -603,8 +616,8 @@ module Playwright
|
|
603
616
|
wrap_impl(@impl.get_by_label(unwrap_impl(text), exact: unwrap_impl(exact)))
|
604
617
|
end
|
605
618
|
|
606
|
-
#
|
607
|
-
# "Country":
|
619
|
+
#
|
620
|
+
# Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder "Country":
|
608
621
|
#
|
609
622
|
# ```html
|
610
623
|
# <input placeholder="Country">
|
@@ -613,15 +626,10 @@ module Playwright
|
|
613
626
|
wrap_impl(@impl.get_by_placeholder(unwrap_impl(text), exact: unwrap_impl(exact)))
|
614
627
|
end
|
615
628
|
|
616
|
-
# Allows locating elements by their [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles),
|
617
|
-
# [ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and
|
618
|
-
# [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). Note that role selector **does not replace**
|
619
|
-
# accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
620
629
|
#
|
621
|
-
# Note that
|
622
|
-
#
|
623
|
-
# can find all the [supported roles here](https://www.w3.org/TR/wai-aria-1.2/#role_definitions). ARIA guidelines **do not
|
624
|
-
# recommend** duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values.
|
630
|
+
# Allows locating elements by their [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles), [ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). Note that role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
631
|
+
#
|
632
|
+
# Note that many html elements have an implicitly [defined role](https://w3c.github.io/html-aam/#html-element-role-mappings) that is recognized by the role selector. You can find all the [supported roles here](https://www.w3.org/TR/wai-aria-1.2/#role_definitions). ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values.
|
625
633
|
def get_by_role(
|
626
634
|
role,
|
627
635
|
checked: nil,
|
@@ -636,12 +644,13 @@ module Playwright
|
|
636
644
|
wrap_impl(@impl.get_by_role(unwrap_impl(role), checked: unwrap_impl(checked), disabled: unwrap_impl(disabled), exact: unwrap_impl(exact), expanded: unwrap_impl(expanded), includeHidden: unwrap_impl(includeHidden), level: unwrap_impl(level), name: unwrap_impl(name), pressed: unwrap_impl(pressed), selected: unwrap_impl(selected)))
|
637
645
|
end
|
638
646
|
|
639
|
-
#
|
640
|
-
# [`method: Selectors.setTestIdAttribute`] to configure a different test id attribute if necessary.
|
647
|
+
#
|
648
|
+
# Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use [`method: Selectors.setTestIdAttribute`] to configure a different test id attribute if necessary.
|
641
649
|
def get_by_test_id(testId)
|
642
650
|
wrap_impl(@impl.get_by_test_id(unwrap_impl(testId)))
|
643
651
|
end
|
644
652
|
|
653
|
+
#
|
645
654
|
# Allows locating elements that contain given text. Consider the following DOM structure:
|
646
655
|
#
|
647
656
|
# ```html
|
@@ -668,17 +677,16 @@ module Playwright
|
|
668
677
|
# page.get_by_text(re.compile("^hello$", re.IGNORECASE))
|
669
678
|
# ```
|
670
679
|
#
|
671
|
-
# See also [`method: Locator.filter`] that allows to match by another criteria, like an accessible role, and then filter
|
672
|
-
# by the text content.
|
680
|
+
# See also [`method: Locator.filter`] that allows to match by another criteria, like an accessible role, and then filter by the text content.
|
673
681
|
#
|
674
|
-
#
|
675
|
-
#
|
676
|
-
#
|
677
|
-
# example, locating by text `"Log in"` matches `<input type=button value="Log in">`.
|
682
|
+
# **NOTE**: Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
|
683
|
+
#
|
684
|
+
# **NOTE**: Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For example, locating by text `"Log in"` matches `<input type=button value="Log in">`.
|
678
685
|
def get_by_text(text, exact: nil)
|
679
686
|
wrap_impl(@impl.get_by_text(unwrap_impl(text), exact: unwrap_impl(exact)))
|
680
687
|
end
|
681
688
|
|
689
|
+
#
|
682
690
|
# Allows locating elements by their title. For example, this method will find the button by its title "Place the order":
|
683
691
|
#
|
684
692
|
# ```html
|
@@ -688,6 +696,7 @@ module Playwright
|
|
688
696
|
wrap_impl(@impl.get_by_title(unwrap_impl(text), exact: unwrap_impl(exact)))
|
689
697
|
end
|
690
698
|
|
699
|
+
#
|
691
700
|
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
692
701
|
# last redirect. If can not go back, returns `null`.
|
693
702
|
#
|
@@ -696,6 +705,7 @@ module Playwright
|
|
696
705
|
wrap_impl(@impl.go_back(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
697
706
|
end
|
698
707
|
|
708
|
+
#
|
699
709
|
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
700
710
|
# last redirect. If can not go forward, returns `null`.
|
701
711
|
#
|
@@ -704,6 +714,7 @@ module Playwright
|
|
704
714
|
wrap_impl(@impl.go_forward(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
705
715
|
end
|
706
716
|
|
717
|
+
#
|
707
718
|
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first
|
708
719
|
# non-redirect response.
|
709
720
|
#
|
@@ -718,28 +729,25 @@ module Playwright
|
|
718
729
|
# Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
|
719
730
|
# [`method: Response.status`].
|
720
731
|
#
|
721
|
-
#
|
732
|
+
# **NOTE**: The method either throws an error or returns a main resource response. The only exceptions are navigation to
|
722
733
|
# `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
|
723
|
-
# > NOTE: Headless mode doesn't support navigation to a PDF document. See the
|
724
|
-
# [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
725
734
|
#
|
726
|
-
#
|
735
|
+
# **NOTE**: Headless mode doesn't support navigation to a PDF document. See the
|
736
|
+
# [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
727
737
|
def goto(url, referer: nil, timeout: nil, waitUntil: nil)
|
728
738
|
wrap_impl(@impl.goto(unwrap_impl(url), referer: unwrap_impl(referer), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
729
739
|
end
|
730
740
|
|
741
|
+
#
|
731
742
|
# This method hovers over an element matching `selector` by performing the following steps:
|
732
743
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
733
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
734
|
-
# element is detached during the checks, the whole action is retried.
|
744
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
735
745
|
# 1. Scroll the element into view if needed.
|
736
746
|
# 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
|
737
747
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
738
748
|
#
|
739
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
740
|
-
# zero timeout disables this.
|
741
|
-
#
|
742
|
-
# Shortcut for main frame's [`method: Frame.hover`].
|
749
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
750
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
743
751
|
def hover(
|
744
752
|
selector,
|
745
753
|
force: nil,
|
@@ -752,110 +760,124 @@ module Playwright
|
|
752
760
|
wrap_impl(@impl.hover(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
753
761
|
end
|
754
762
|
|
763
|
+
#
|
755
764
|
# Returns `element.innerHTML`.
|
756
765
|
def inner_html(selector, strict: nil, timeout: nil)
|
757
766
|
wrap_impl(@impl.inner_html(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
758
767
|
end
|
759
768
|
|
769
|
+
#
|
760
770
|
# Returns `element.innerText`.
|
761
771
|
def inner_text(selector, strict: nil, timeout: nil)
|
762
772
|
wrap_impl(@impl.inner_text(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
763
773
|
end
|
764
774
|
|
775
|
+
#
|
765
776
|
# Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.
|
766
777
|
#
|
767
|
-
# Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated
|
768
|
-
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.
|
778
|
+
# Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.
|
769
779
|
def input_value(selector, strict: nil, timeout: nil)
|
770
780
|
wrap_impl(@impl.input_value(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
771
781
|
end
|
772
782
|
|
783
|
+
#
|
773
784
|
# Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
774
785
|
def checked?(selector, strict: nil, timeout: nil)
|
775
786
|
wrap_impl(@impl.checked?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
776
787
|
end
|
777
788
|
|
789
|
+
#
|
778
790
|
# Indicates that the page has been closed.
|
779
791
|
def closed?
|
780
792
|
wrap_impl(@impl.closed?)
|
781
793
|
end
|
782
794
|
|
795
|
+
#
|
783
796
|
# Returns whether the element is disabled, the opposite of [enabled](../actionability.md#enabled).
|
784
797
|
def disabled?(selector, strict: nil, timeout: nil)
|
785
798
|
wrap_impl(@impl.disabled?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
786
799
|
end
|
787
800
|
|
801
|
+
#
|
788
802
|
# Returns whether the element is [editable](../actionability.md#editable).
|
789
803
|
def editable?(selector, strict: nil, timeout: nil)
|
790
804
|
wrap_impl(@impl.editable?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
791
805
|
end
|
792
806
|
|
807
|
+
#
|
793
808
|
# Returns whether the element is [enabled](../actionability.md#enabled).
|
794
809
|
def enabled?(selector, strict: nil, timeout: nil)
|
795
810
|
wrap_impl(@impl.enabled?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
796
811
|
end
|
797
812
|
|
798
|
-
#
|
799
|
-
# match any elements is considered hidden.
|
813
|
+
#
|
814
|
+
# Returns whether the element is hidden, the opposite of [visible](../actionability.md#visible). `selector` that does not match any elements is considered hidden.
|
800
815
|
def hidden?(selector, strict: nil, timeout: nil)
|
801
816
|
wrap_impl(@impl.hidden?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
802
817
|
end
|
803
818
|
|
804
|
-
#
|
805
|
-
# considered not visible.
|
819
|
+
#
|
820
|
+
# Returns whether the element is [visible](../actionability.md#visible). `selector` that does not match any elements is considered not visible.
|
806
821
|
def visible?(selector, strict: nil, timeout: nil)
|
807
822
|
wrap_impl(@impl.visible?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
808
823
|
end
|
809
824
|
|
810
|
-
#
|
811
|
-
#
|
812
|
-
# on different DOM elements. That would happen if the DOM structure between those actions has changed.
|
825
|
+
#
|
826
|
+
# The method returns an element locator that can be used to perform actions on this page / frame.
|
827
|
+
# Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
|
813
828
|
#
|
814
829
|
# [Learn more about locators](../locators.md).
|
815
830
|
def locator(selector, has: nil, hasText: nil)
|
816
831
|
wrap_impl(@impl.locator(unwrap_impl(selector), has: unwrap_impl(has), hasText: unwrap_impl(hasText)))
|
817
832
|
end
|
818
833
|
|
834
|
+
#
|
819
835
|
# The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
|
820
836
|
def main_frame
|
821
837
|
wrap_impl(@impl.main_frame)
|
822
838
|
end
|
823
839
|
|
840
|
+
#
|
824
841
|
# Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
|
825
842
|
def opener
|
826
843
|
wrap_impl(@impl.opener)
|
827
844
|
end
|
828
845
|
|
829
|
-
#
|
830
|
-
#
|
846
|
+
#
|
847
|
+
# Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume'
|
848
|
+
# button in the page overlay or to call `playwright.resume()` in the DevTools console.
|
831
849
|
#
|
832
850
|
# User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
|
833
851
|
# the place it was paused.
|
834
852
|
#
|
835
|
-
#
|
836
|
-
# [`method: BrowserType.launch`].
|
853
|
+
# **NOTE**: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in
|
854
|
+
# the [`method: BrowserType.launch`].
|
837
855
|
def pause
|
838
856
|
wrap_impl(@impl.pause)
|
839
857
|
end
|
840
858
|
|
859
|
+
#
|
841
860
|
# Returns the PDF buffer.
|
842
861
|
#
|
843
|
-
#
|
862
|
+
# **NOTE**: Generating a pdf is currently only supported in Chromium headless.
|
844
863
|
#
|
845
864
|
# `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
|
846
865
|
# [`method: Page.emulateMedia`] before calling `page.pdf()`:
|
847
866
|
#
|
848
|
-
#
|
867
|
+
# **NOTE**: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
|
849
868
|
# [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
|
850
869
|
# force rendering of exact colors.
|
851
870
|
#
|
871
|
+
# **Usage**
|
872
|
+
#
|
852
873
|
# ```python sync
|
853
874
|
# # generates a pdf with "screen" media type.
|
854
875
|
# page.emulate_media(media="screen")
|
855
876
|
# page.pdf(path="page.pdf")
|
856
877
|
# ```
|
857
878
|
#
|
858
|
-
# The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled
|
879
|
+
# The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled
|
880
|
+
# values are treated as pixels.
|
859
881
|
#
|
860
882
|
# A few examples:
|
861
883
|
# - `page.pdf({width: 100})` - prints with width set to 100 pixels
|
@@ -881,8 +903,8 @@ module Playwright
|
|
881
903
|
# - `A5`: 5.83in x 8.27in
|
882
904
|
# - `A6`: 4.13in x 5.83in
|
883
905
|
#
|
884
|
-
#
|
885
|
-
# are not evaluated. > 2. Page styles are not visible inside templates.
|
906
|
+
# **NOTE**: `headerTemplate` and `footerTemplate` markup have the following limitations: > 1. Script tags inside
|
907
|
+
# templates are not evaluated. > 2. Page styles are not visible inside templates.
|
886
908
|
def pdf(
|
887
909
|
displayHeaderFooter: nil,
|
888
910
|
footerTemplate: nil,
|
@@ -900,10 +922,12 @@ module Playwright
|
|
900
922
|
wrap_impl(@impl.pdf(displayHeaderFooter: unwrap_impl(displayHeaderFooter), footerTemplate: unwrap_impl(footerTemplate), format: unwrap_impl(format), headerTemplate: unwrap_impl(headerTemplate), height: unwrap_impl(height), landscape: unwrap_impl(landscape), margin: unwrap_impl(margin), pageRanges: unwrap_impl(pageRanges), path: unwrap_impl(path), preferCSSPageSize: unwrap_impl(preferCSSPageSize), printBackground: unwrap_impl(printBackground), scale: unwrap_impl(scale), width: unwrap_impl(width)))
|
901
923
|
end
|
902
924
|
|
925
|
+
#
|
903
926
|
# Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
904
927
|
#
|
905
|
-
# `key` can specify the intended
|
906
|
-
# value or a single character to
|
928
|
+
# `key` can specify the intended
|
929
|
+
# [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
|
930
|
+
# generate the text for. A superset of the `key` values can be found
|
907
931
|
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
908
932
|
#
|
909
933
|
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
@@ -913,12 +937,14 @@ module Playwright
|
|
913
937
|
#
|
914
938
|
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
915
939
|
#
|
916
|
-
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
|
917
|
-
# texts.
|
940
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
|
941
|
+
# respective texts.
|
918
942
|
#
|
919
943
|
# Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
|
920
944
|
# modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
921
945
|
#
|
946
|
+
# **Usage**
|
947
|
+
#
|
922
948
|
# ```python sync
|
923
949
|
# page = browser.new_page()
|
924
950
|
# page.goto("https://keycode.info")
|
@@ -940,40 +966,38 @@ module Playwright
|
|
940
966
|
wrap_impl(@impl.press(unwrap_impl(selector), unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
941
967
|
end
|
942
968
|
|
943
|
-
# > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
|
944
969
|
#
|
945
970
|
# The method finds an element matching the specified selector within the page. If no elements match the selector, the
|
946
971
|
# return value resolves to `null`. To wait for an element on the page, use [`method: Locator.waitFor`].
|
947
|
-
#
|
948
|
-
# Shortcut for main frame's [`method: Frame.querySelector`].
|
949
972
|
def query_selector(selector, strict: nil)
|
950
973
|
wrap_impl(@impl.query_selector(unwrap_impl(selector), strict: unwrap_impl(strict)))
|
951
974
|
end
|
952
975
|
|
953
|
-
# > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
|
954
976
|
#
|
955
977
|
# The method finds all elements matching the specified selector within the page. If no elements match the selector, the
|
956
978
|
# return value resolves to `[]`.
|
957
|
-
#
|
958
|
-
# Shortcut for main frame's [`method: Frame.querySelectorAll`].
|
959
979
|
def query_selector_all(selector)
|
960
980
|
wrap_impl(@impl.query_selector_all(unwrap_impl(selector)))
|
961
981
|
end
|
962
982
|
|
963
|
-
#
|
964
|
-
#
|
983
|
+
#
|
984
|
+
# This method reloads the current page, in the same way as if the user had triggered a browser refresh.
|
985
|
+
# Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
986
|
+
# last redirect.
|
965
987
|
def reload(timeout: nil, waitUntil: nil)
|
966
988
|
wrap_impl(@impl.reload(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
967
989
|
end
|
968
990
|
|
991
|
+
#
|
969
992
|
# Routing provides the capability to modify network requests that are made by a page.
|
970
993
|
#
|
971
994
|
# Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
972
995
|
#
|
973
|
-
#
|
974
|
-
#
|
975
|
-
# [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
|
976
|
-
#
|
996
|
+
# **NOTE**: The handler will only be called for the first url if the response is a redirect.
|
997
|
+
#
|
998
|
+
# **NOTE**: [`method: Page.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
999
|
+
#
|
1000
|
+
# **Usage**
|
977
1001
|
#
|
978
1002
|
# An example of a naive handler that aborts all image requests:
|
979
1003
|
#
|
@@ -993,8 +1017,7 @@ module Playwright
|
|
993
1017
|
# browser.close()
|
994
1018
|
# ```
|
995
1019
|
#
|
996
|
-
# It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
|
997
|
-
# post data, and leaving all other requests as is:
|
1020
|
+
# It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
|
998
1021
|
#
|
999
1022
|
# ```python sync
|
1000
1023
|
# def handle_route(route):
|
@@ -1010,21 +1033,20 @@ module Playwright
|
|
1010
1033
|
#
|
1011
1034
|
# To remove a route with its handler you can use [`method: Page.unroute`].
|
1012
1035
|
#
|
1013
|
-
#
|
1036
|
+
# **NOTE**: Enabling routing disables http cache.
|
1014
1037
|
def route(url, handler, times: nil)
|
1015
1038
|
wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler), times: unwrap_impl(times)))
|
1016
1039
|
end
|
1017
1040
|
|
1018
|
-
# If specified the network requests that are made in the page will be served from the HAR file. Read more about
|
1019
|
-
# [Replaying from HAR](../network.md#replaying-from-har).
|
1020
1041
|
#
|
1021
|
-
#
|
1022
|
-
#
|
1023
|
-
# request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
1042
|
+
# If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
|
1043
|
+
#
|
1044
|
+
# Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
1024
1045
|
def route_from_har(har, notFound: nil, update: nil, url: nil)
|
1025
1046
|
wrap_impl(@impl.route_from_har(unwrap_impl(har), notFound: unwrap_impl(notFound), update: unwrap_impl(update), url: unwrap_impl(url)))
|
1026
1047
|
end
|
1027
1048
|
|
1049
|
+
#
|
1028
1050
|
# Returns the buffer with the captured screenshot.
|
1029
1051
|
def screenshot(
|
1030
1052
|
animations: nil,
|
@@ -1041,17 +1063,17 @@ module Playwright
|
|
1041
1063
|
wrap_impl(@impl.screenshot(animations: unwrap_impl(animations), caret: unwrap_impl(caret), clip: unwrap_impl(clip), fullPage: unwrap_impl(fullPage), mask: unwrap_impl(mask), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), scale: unwrap_impl(scale), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
|
1042
1064
|
end
|
1043
1065
|
|
1044
|
-
# This method waits for an element matching `selector`, waits for [actionability](../actionability.md) checks, waits until
|
1045
|
-
# all specified options are present in the `<select>` element and selects these options.
|
1046
1066
|
#
|
1047
|
-
#
|
1048
|
-
#
|
1049
|
-
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
|
1067
|
+
# This method waits for an element matching `selector`, waits for [actionability](../actionability.md) checks, waits until all specified options are present in the `<select>` element and selects these options.
|
1068
|
+
#
|
1069
|
+
# If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
|
1050
1070
|
#
|
1051
1071
|
# Returns the array of option values that have been successfully selected.
|
1052
1072
|
#
|
1053
1073
|
# Triggers a `change` and `input` event once all the provided options have been selected.
|
1054
1074
|
#
|
1075
|
+
# **Usage**
|
1076
|
+
#
|
1055
1077
|
# ```python sync
|
1056
1078
|
# # single selection matching the value
|
1057
1079
|
# page.select_option("select#colors", "blue")
|
@@ -1060,8 +1082,6 @@ module Playwright
|
|
1060
1082
|
# # multiple selection
|
1061
1083
|
# page.select_option("select#colors", value=["red", "green", "blue"])
|
1062
1084
|
# ```
|
1063
|
-
#
|
1064
|
-
# Shortcut for main frame's [`method: Frame.selectOption`].
|
1065
1085
|
def select_option(
|
1066
1086
|
selector,
|
1067
1087
|
element: nil,
|
@@ -1075,21 +1095,19 @@ module Playwright
|
|
1075
1095
|
wrap_impl(@impl.select_option(unwrap_impl(selector), element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
1076
1096
|
end
|
1077
1097
|
|
1098
|
+
#
|
1078
1099
|
# This method checks or unchecks an element matching `selector` by performing the following steps:
|
1079
1100
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
1080
1101
|
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
|
1081
1102
|
# 1. If the element already has the right checked state, this method returns immediately.
|
1082
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
1083
|
-
# element is detached during the checks, the whole action is retried.
|
1103
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
1084
1104
|
# 1. Scroll the element into view if needed.
|
1085
1105
|
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
1086
1106
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
1087
1107
|
# 1. Ensure that the element is now checked or unchecked. If not, this method throws.
|
1088
1108
|
#
|
1089
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1090
|
-
# zero timeout disables this.
|
1091
|
-
#
|
1092
|
-
# Shortcut for main frame's [`method: Frame.setChecked`].
|
1109
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1110
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
1093
1111
|
def set_checked(
|
1094
1112
|
selector,
|
1095
1113
|
checked,
|
@@ -1107,6 +1125,7 @@ module Playwright
|
|
1107
1125
|
end
|
1108
1126
|
alias_method :content=, :set_content
|
1109
1127
|
|
1128
|
+
#
|
1110
1129
|
# This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
1111
1130
|
# - [`method: Page.goBack`]
|
1112
1131
|
# - [`method: Page.goForward`]
|
@@ -1116,36 +1135,37 @@ module Playwright
|
|
1116
1135
|
# - [`method: Page.waitForNavigation`]
|
1117
1136
|
# - [`method: Page.waitForURL`]
|
1118
1137
|
#
|
1119
|
-
#
|
1138
|
+
# **NOTE**: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
|
1120
1139
|
# [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
|
1121
1140
|
def set_default_navigation_timeout(timeout)
|
1122
1141
|
wrap_impl(@impl.set_default_navigation_timeout(unwrap_impl(timeout)))
|
1123
1142
|
end
|
1124
1143
|
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
1125
1144
|
|
1145
|
+
#
|
1126
1146
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
1127
1147
|
#
|
1128
|
-
#
|
1148
|
+
# **NOTE**: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`].
|
1129
1149
|
def set_default_timeout(timeout)
|
1130
1150
|
wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
|
1131
1151
|
end
|
1132
1152
|
alias_method :default_timeout=, :set_default_timeout
|
1133
1153
|
|
1154
|
+
#
|
1134
1155
|
# The extra HTTP headers will be sent with every request the page initiates.
|
1135
1156
|
#
|
1136
|
-
#
|
1157
|
+
# **NOTE**: [`method: Page.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
|
1137
1158
|
def set_extra_http_headers(headers)
|
1138
1159
|
wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
|
1139
1160
|
end
|
1140
1161
|
alias_method :extra_http_headers=, :set_extra_http_headers
|
1141
1162
|
|
1163
|
+
#
|
1142
1164
|
# Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
|
1143
1165
|
# are resolved relative to the current working directory. For empty array, clears the selected files.
|
1144
1166
|
#
|
1145
1167
|
# This method expects `selector` to point to an
|
1146
|
-
# [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the
|
1147
|
-
# `<label>` element that has an associated
|
1148
|
-
# [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.
|
1168
|
+
# [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.
|
1149
1169
|
def set_input_files(
|
1150
1170
|
selector,
|
1151
1171
|
files,
|
@@ -1155,13 +1175,14 @@ module Playwright
|
|
1155
1175
|
wrap_impl(@impl.set_input_files(unwrap_impl(selector), unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
1156
1176
|
end
|
1157
1177
|
|
1178
|
+
#
|
1158
1179
|
# In the case of multiple pages in a single browser, each page can have its own viewport size. However,
|
1159
1180
|
# [`method: Browser.newContext`] allows to set viewport size (and more) for all pages in the context at once.
|
1160
1181
|
#
|
1161
|
-
# [`method: Page.setViewportSize`] will resize the page. A lot of websites don't expect phones to change size, so you
|
1162
|
-
#
|
1163
|
-
#
|
1164
|
-
#
|
1182
|
+
# [`method: Page.setViewportSize`] will resize the page. A lot of websites don't expect phones to change size, so you should set the
|
1183
|
+
# viewport size before navigating to the page. [`method: Page.setViewportSize`] will also reset `screen` size, use [`method: Browser.newContext`] with `screen` and `viewport` parameters if you need better control of these properties.
|
1184
|
+
#
|
1185
|
+
# **Usage**
|
1165
1186
|
#
|
1166
1187
|
# ```python sync
|
1167
1188
|
# page = browser.new_page()
|
@@ -1173,20 +1194,18 @@ module Playwright
|
|
1173
1194
|
end
|
1174
1195
|
alias_method :viewport_size=, :set_viewport_size
|
1175
1196
|
|
1197
|
+
#
|
1176
1198
|
# This method taps an element matching `selector` by performing the following steps:
|
1177
1199
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
1178
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
1179
|
-
# element is detached during the checks, the whole action is retried.
|
1200
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
1180
1201
|
# 1. Scroll the element into view if needed.
|
1181
1202
|
# 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
|
1182
1203
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
1183
1204
|
#
|
1184
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1185
|
-
# zero timeout disables this.
|
1205
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1206
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
1186
1207
|
#
|
1187
|
-
#
|
1188
|
-
#
|
1189
|
-
# Shortcut for main frame's [`method: Frame.tap`].
|
1208
|
+
# **NOTE**: [`method: Page.tap`] requires that the `hasTouch` option of the browser context be set to true.
|
1190
1209
|
def tap_point(
|
1191
1210
|
selector,
|
1192
1211
|
force: nil,
|
@@ -1199,27 +1218,30 @@ module Playwright
|
|
1199
1218
|
wrap_impl(@impl.tap_point(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
1200
1219
|
end
|
1201
1220
|
|
1221
|
+
#
|
1202
1222
|
# Returns `element.textContent`.
|
1203
1223
|
def text_content(selector, strict: nil, timeout: nil)
|
1204
1224
|
wrap_impl(@impl.text_content(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
1205
1225
|
end
|
1206
1226
|
|
1207
|
-
#
|
1227
|
+
#
|
1228
|
+
# Returns the page's title.
|
1208
1229
|
def title
|
1209
1230
|
wrap_impl(@impl.title)
|
1210
1231
|
end
|
1211
1232
|
|
1233
|
+
#
|
1212
1234
|
# Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
|
1213
1235
|
# fine-grained keyboard events. To fill values in form fields, use [`method: Page.fill`].
|
1214
1236
|
#
|
1215
1237
|
# To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
|
1216
1238
|
#
|
1239
|
+
# **Usage**
|
1240
|
+
#
|
1217
1241
|
# ```python sync
|
1218
1242
|
# page.type("#mytextarea", "hello") # types instantly
|
1219
1243
|
# page.type("#mytextarea", "world", delay=100) # types slower, like a user
|
1220
1244
|
# ```
|
1221
|
-
#
|
1222
|
-
# Shortcut for main frame's [`method: Frame.type`].
|
1223
1245
|
def type(
|
1224
1246
|
selector,
|
1225
1247
|
text,
|
@@ -1230,21 +1252,18 @@ module Playwright
|
|
1230
1252
|
wrap_impl(@impl.type(unwrap_impl(selector), unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
1231
1253
|
end
|
1232
1254
|
|
1255
|
+
#
|
1233
1256
|
# This method unchecks an element matching `selector` by performing the following steps:
|
1234
1257
|
# 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
1235
|
-
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
|
1236
|
-
#
|
1237
|
-
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the
|
1238
|
-
# element is detached during the checks, the whole action is retried.
|
1258
|
+
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already unchecked, this method returns immediately.
|
1259
|
+
# 1. Wait for [actionability](../actionability.md) checks on the matched element, unless `force` option is set. If the element is detached during the checks, the whole action is retried.
|
1239
1260
|
# 1. Scroll the element into view if needed.
|
1240
1261
|
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
1241
1262
|
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
1242
1263
|
# 1. Ensure that the element is now unchecked. If not, this method throws.
|
1243
1264
|
#
|
1244
|
-
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1245
|
-
# zero timeout disables this.
|
1246
|
-
#
|
1247
|
-
# Shortcut for main frame's [`method: Frame.uncheck`].
|
1265
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
1266
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
1248
1267
|
def uncheck(
|
1249
1268
|
selector,
|
1250
1269
|
force: nil,
|
@@ -1256,16 +1275,18 @@ module Playwright
|
|
1256
1275
|
wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
1257
1276
|
end
|
1258
1277
|
|
1259
|
-
#
|
1278
|
+
#
|
1279
|
+
# Removes a route created with [`method: Page.route`]. When `handler` is not specified, removes all routes for
|
1280
|
+
# the `url`.
|
1260
1281
|
def unroute(url, handler: nil)
|
1261
1282
|
wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
|
1262
1283
|
end
|
1263
1284
|
|
1264
|
-
# Shortcut for main frame's [`method: Frame.url`].
|
1265
1285
|
def url
|
1266
1286
|
wrap_impl(@impl.url)
|
1267
1287
|
end
|
1268
1288
|
|
1289
|
+
#
|
1269
1290
|
# Video object associated with this page.
|
1270
1291
|
def video
|
1271
1292
|
wrap_impl(@impl.video)
|
@@ -1275,23 +1296,28 @@ module Playwright
|
|
1275
1296
|
wrap_impl(@impl.viewport_size)
|
1276
1297
|
end
|
1277
1298
|
|
1299
|
+
#
|
1278
1300
|
# Performs action and waits for a `ConsoleMessage` to be logged by in the page. If predicate is provided, it passes
|
1279
|
-
# `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to return a truthy value.
|
1280
|
-
# throw an error if the page is closed before the [`event: Page.console`] event is fired.
|
1301
|
+
# `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to return a truthy value.
|
1302
|
+
# Will throw an error if the page is closed before the [`event: Page.console`] event is fired.
|
1281
1303
|
def expect_console_message(predicate: nil, timeout: nil, &block)
|
1282
1304
|
wrap_impl(@impl.expect_console_message(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1283
1305
|
end
|
1284
1306
|
|
1285
|
-
#
|
1286
|
-
#
|
1287
|
-
#
|
1307
|
+
#
|
1308
|
+
# Performs action and waits for a new `Download`. If predicate is provided, it passes
|
1309
|
+
# `Download` value into the `predicate` function and waits for `predicate(download)` to return a truthy value.
|
1310
|
+
# Will throw an error if the page is closed before the download event is fired.
|
1288
1311
|
def expect_download(predicate: nil, timeout: nil, &block)
|
1289
1312
|
wrap_impl(@impl.expect_download(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1290
1313
|
end
|
1291
1314
|
|
1315
|
+
#
|
1292
1316
|
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
1293
1317
|
# value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
|
1294
1318
|
#
|
1319
|
+
# **Usage**
|
1320
|
+
#
|
1295
1321
|
# ```python sync
|
1296
1322
|
# with page.expect_event("framenavigated") as event_info:
|
1297
1323
|
# page.get_by_role("button")
|
@@ -1301,15 +1327,19 @@ module Playwright
|
|
1301
1327
|
wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1302
1328
|
end
|
1303
1329
|
|
1304
|
-
#
|
1305
|
-
#
|
1306
|
-
# the
|
1330
|
+
#
|
1331
|
+
# Performs action and waits for a new `FileChooser` to be created. If predicate is provided, it passes
|
1332
|
+
# `FileChooser` value into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value.
|
1333
|
+
# Will throw an error if the page is closed before the file chooser is opened.
|
1307
1334
|
def expect_file_chooser(predicate: nil, timeout: nil, &block)
|
1308
1335
|
wrap_impl(@impl.expect_file_chooser(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1309
1336
|
end
|
1310
1337
|
|
1338
|
+
#
|
1311
1339
|
# Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
|
1312
1340
|
#
|
1341
|
+
# **Usage**
|
1342
|
+
#
|
1313
1343
|
# The [`method: Page.waitForFunction`] can be used to observe viewport size change:
|
1314
1344
|
#
|
1315
1345
|
# ```python sync
|
@@ -1333,17 +1363,18 @@ module Playwright
|
|
1333
1363
|
# selector = ".foo"
|
1334
1364
|
# page.wait_for_function("selector => !!document.querySelector(selector)", selector)
|
1335
1365
|
# ```
|
1336
|
-
#
|
1337
|
-
# Shortcut for main frame's [`method: Frame.waitForFunction`].
|
1338
1366
|
def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
|
1339
1367
|
wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
|
1340
1368
|
end
|
1341
1369
|
|
1370
|
+
#
|
1342
1371
|
# Returns when the required load state has been reached.
|
1343
1372
|
#
|
1344
1373
|
# This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
|
1345
1374
|
# when this method is called. If current document has already reached the required state, resolves immediately.
|
1346
1375
|
#
|
1376
|
+
# **Usage**
|
1377
|
+
#
|
1347
1378
|
# ```python sync
|
1348
1379
|
# page.get_by_role("button").click() # click triggers navigation.
|
1349
1380
|
# page.wait_for_load_state() # the promise resolves after "load" event.
|
@@ -1353,19 +1384,20 @@ module Playwright
|
|
1353
1384
|
# with page.expect_popup() as page_info:
|
1354
1385
|
# page.get_by_role("button").click() # click triggers a popup.
|
1355
1386
|
# popup = page_info.value
|
1356
|
-
#
|
1387
|
+
# # Wait for the "DOMContentLoaded" event.
|
1357
1388
|
# popup.wait_for_load_state("domcontentloaded")
|
1358
1389
|
# print(popup.title()) # popup is ready to use.
|
1359
1390
|
# ```
|
1360
|
-
#
|
1361
|
-
# Shortcut for main frame's [`method: Frame.waitForLoadState`].
|
1362
1391
|
def wait_for_load_state(state: nil, timeout: nil)
|
1363
1392
|
wrap_impl(@impl.wait_for_load_state(state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
|
1364
1393
|
end
|
1365
1394
|
|
1366
|
-
#
|
1367
|
-
#
|
1368
|
-
#
|
1395
|
+
#
|
1396
|
+
# Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation
|
1397
|
+
# will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
|
1398
|
+
# History API usage, the navigation will resolve with `null`.
|
1399
|
+
#
|
1400
|
+
# **Usage**
|
1369
1401
|
#
|
1370
1402
|
# This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
|
1371
1403
|
# cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
|
@@ -1373,60 +1405,66 @@ module Playwright
|
|
1373
1405
|
#
|
1374
1406
|
# ```python sync
|
1375
1407
|
# with page.expect_navigation():
|
1376
|
-
#
|
1408
|
+
# # This action triggers the navigation after a timeout.
|
1409
|
+
# page.get_by_text("Navigate after timeout").click()
|
1377
1410
|
# # Resolves after navigation has finished
|
1378
1411
|
# ```
|
1379
1412
|
#
|
1380
|
-
#
|
1381
|
-
#
|
1382
|
-
#
|
1383
|
-
# Shortcut for main frame's [`method: Frame.waitForNavigation`].
|
1413
|
+
# **NOTE**: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered
|
1414
|
+
# a navigation.
|
1384
1415
|
def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
|
1385
1416
|
wrap_impl(@impl.expect_navigation(timeout: unwrap_impl(timeout), url: unwrap_impl(url), waitUntil: unwrap_impl(waitUntil), &wrap_block_call(block)))
|
1386
1417
|
end
|
1387
1418
|
|
1388
|
-
#
|
1389
|
-
#
|
1390
|
-
#
|
1419
|
+
#
|
1420
|
+
# Performs action and waits for a popup `Page`. If predicate is provided, it passes
|
1421
|
+
# [Popup] value into the `predicate` function and waits for `predicate(page)` to return a truthy value.
|
1422
|
+
# Will throw an error if the page is closed before the popup event is fired.
|
1391
1423
|
def expect_popup(predicate: nil, timeout: nil, &block)
|
1392
1424
|
wrap_impl(@impl.expect_popup(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1393
1425
|
end
|
1394
1426
|
|
1395
|
-
#
|
1396
|
-
# about events.
|
1427
|
+
#
|
1428
|
+
# Waits for the matching request and returns it. See [waiting for event](../events.md#waiting-for-event) for more details about events.
|
1429
|
+
#
|
1430
|
+
# **Usage**
|
1397
1431
|
#
|
1398
1432
|
# ```python sync
|
1399
1433
|
# with page.expect_request("http://example.com/resource") as first:
|
1400
|
-
# page.click(
|
1434
|
+
# page.get_by_text("trigger request").click()
|
1401
1435
|
# first_request = first.value
|
1402
1436
|
#
|
1403
1437
|
# # or with a lambda
|
1404
1438
|
# with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
|
1405
|
-
# page.click(
|
1439
|
+
# page.get_by_text("trigger request").click()
|
1406
1440
|
# second_request = second.value
|
1407
1441
|
# ```
|
1408
1442
|
def expect_request(urlOrPredicate, timeout: nil, &block)
|
1409
1443
|
wrap_impl(@impl.expect_request(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1410
1444
|
end
|
1411
1445
|
|
1412
|
-
#
|
1413
|
-
#
|
1414
|
-
#
|
1446
|
+
#
|
1447
|
+
# Performs action and waits for a `Request` to finish loading. If predicate is provided, it passes
|
1448
|
+
# `Request` value into the `predicate` function and waits for `predicate(request)` to return a truthy value.
|
1449
|
+
# Will throw an error if the page is closed before the [`event: Page.requestFinished`] event is fired.
|
1415
1450
|
def expect_request_finished(predicate: nil, timeout: nil, &block)
|
1416
1451
|
wrap_impl(@impl.expect_request_finished(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1417
1452
|
end
|
1418
1453
|
|
1454
|
+
#
|
1419
1455
|
# Returns the matched response. See [waiting for event](../events.md#waiting-for-event) for more details about events.
|
1420
1456
|
#
|
1457
|
+
# **Usage**
|
1458
|
+
#
|
1421
1459
|
# ```python sync
|
1422
1460
|
# with page.expect_response("https://example.com/resource") as response_info:
|
1423
|
-
# page.
|
1461
|
+
# page.get_by_text("trigger response").click()
|
1424
1462
|
# response = response_info.value
|
1425
1463
|
# return response.ok
|
1426
1464
|
#
|
1427
1465
|
# # or with a lambda
|
1428
1466
|
# with page.expect_response(lambda response: response.url == "https://example.com" and response.status == 200) as response_info:
|
1429
|
-
# page.
|
1467
|
+
# page.get_by_text("trigger response").click()
|
1430
1468
|
# response = response_info.value
|
1431
1469
|
# return response.ok
|
1432
1470
|
# ```
|
@@ -1434,15 +1472,19 @@ module Playwright
|
|
1434
1472
|
wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1435
1473
|
end
|
1436
1474
|
|
1475
|
+
#
|
1437
1476
|
# Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
|
1438
1477
|
# `detached`.
|
1439
1478
|
#
|
1440
|
-
#
|
1441
|
-
# web-first assertions makes the code wait-for-selector-free.
|
1479
|
+
# **NOTE**: Playwright automatically waits for element to be ready before performing an action. Using
|
1480
|
+
# `Locator` objects and web-first assertions makes the code wait-for-selector-free.
|
1481
|
+
#
|
1482
|
+
# Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become
|
1483
|
+
# visible/hidden). If at the moment of calling the method `selector` already satisfies the condition, the method
|
1484
|
+
# will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the
|
1485
|
+
# function will throw.
|
1442
1486
|
#
|
1443
|
-
#
|
1444
|
-
# the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
|
1445
|
-
# selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
|
1487
|
+
# **Usage**
|
1446
1488
|
#
|
1447
1489
|
# This method works across navigations:
|
1448
1490
|
#
|
@@ -1466,60 +1508,66 @@ module Playwright
|
|
1466
1508
|
wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
|
1467
1509
|
end
|
1468
1510
|
|
1511
|
+
#
|
1469
1512
|
# Waits for the given `timeout` in milliseconds.
|
1470
1513
|
#
|
1471
1514
|
# Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
|
1472
1515
|
# flaky. Use signals such as network events, selectors becoming visible and others instead.
|
1473
1516
|
#
|
1517
|
+
# **Usage**
|
1518
|
+
#
|
1474
1519
|
# ```python sync
|
1475
1520
|
# # wait for 1 second
|
1476
1521
|
# page.wait_for_timeout(1000)
|
1477
1522
|
# ```
|
1478
|
-
#
|
1479
|
-
# Shortcut for main frame's [`method: Frame.waitForTimeout`].
|
1480
1523
|
def wait_for_timeout(timeout)
|
1481
1524
|
wrap_impl(@impl.wait_for_timeout(unwrap_impl(timeout)))
|
1482
1525
|
end
|
1483
1526
|
|
1527
|
+
#
|
1484
1528
|
# Waits for the main frame to navigate to the given URL.
|
1485
1529
|
#
|
1530
|
+
# **Usage**
|
1531
|
+
#
|
1486
1532
|
# ```python sync
|
1487
1533
|
# page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
|
1488
1534
|
# page.wait_for_url("**/target.html")
|
1489
1535
|
# ```
|
1490
|
-
#
|
1491
|
-
# Shortcut for main frame's [`method: Frame.waitForURL`].
|
1492
1536
|
def wait_for_url(url, timeout: nil, waitUntil: nil)
|
1493
1537
|
wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
1494
1538
|
end
|
1495
1539
|
|
1496
|
-
#
|
1497
|
-
#
|
1498
|
-
#
|
1540
|
+
#
|
1541
|
+
# Performs action and waits for a new `WebSocket`. If predicate is provided, it passes
|
1542
|
+
# `WebSocket` value into the `predicate` function and waits for `predicate(webSocket)` to return a truthy value.
|
1543
|
+
# Will throw an error if the page is closed before the WebSocket event is fired.
|
1499
1544
|
def expect_websocket(predicate: nil, timeout: nil, &block)
|
1500
1545
|
wrap_impl(@impl.expect_websocket(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1501
1546
|
end
|
1502
1547
|
|
1503
|
-
#
|
1504
|
-
#
|
1505
|
-
# the worker
|
1548
|
+
#
|
1549
|
+
# Performs action and waits for a new `Worker`. If predicate is provided, it passes
|
1550
|
+
# `Worker` value into the `predicate` function and waits for `predicate(worker)` to return a truthy value.
|
1551
|
+
# Will throw an error if the page is closed before the worker event is fired.
|
1506
1552
|
def expect_worker(predicate: nil, timeout: nil, &block)
|
1507
1553
|
wrap_impl(@impl.expect_worker(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1508
1554
|
end
|
1509
1555
|
|
1556
|
+
#
|
1510
1557
|
# This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
|
1511
1558
|
# associated with the page.
|
1512
1559
|
#
|
1513
|
-
#
|
1560
|
+
# **NOTE**: This does not contain ServiceWorkers
|
1514
1561
|
def workers
|
1515
1562
|
wrap_impl(@impl.workers)
|
1516
1563
|
end
|
1517
1564
|
|
1518
|
-
# > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
|
1519
1565
|
#
|
1520
|
-
#
|
1521
|
-
#
|
1522
|
-
#
|
1566
|
+
# **NOTE**: In most cases, you should use [`method: Page.waitForEvent`].
|
1567
|
+
#
|
1568
|
+
# Waits for given `event` to fire. If predicate is provided, it passes
|
1569
|
+
# event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
|
1570
|
+
# Will throw an error if the page is closed before the `event` is fired.
|
1523
1571
|
def wait_for_event(event, predicate: nil, timeout: nil)
|
1524
1572
|
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
1525
1573
|
end
|