playwright-ruby-client 0.0.8 → 1.58.1.alpha1
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/AGENTS.md +4 -0
- data/CLAUDE/api_generation.md +28 -0
- data/CLAUDE/ci_expectations.md +23 -0
- data/CLAUDE/gem_release_flow.md +39 -0
- data/CLAUDE/past_upgrade_pr_patterns.md +42 -0
- data/CLAUDE/playwright_upgrade_workflow.md +35 -0
- data/CLAUDE/rspec_debugging.md +30 -0
- data/CLAUDE/unimplemented_examples.md +18 -0
- data/CLAUDE.md +32 -0
- data/CONTRIBUTING.md +5 -0
- data/README.md +60 -16
- data/documentation/README.md +33 -0
- data/documentation/babel.config.js +3 -0
- data/documentation/docs/api/api_request.md +7 -0
- data/documentation/docs/api/api_request_context.md +298 -0
- data/documentation/docs/api/api_response.md +114 -0
- data/documentation/docs/api/browser.md +237 -0
- data/documentation/docs/api/browser_context.md +503 -0
- data/documentation/docs/api/browser_type.md +184 -0
- data/documentation/docs/api/cdp_session.md +44 -0
- data/documentation/docs/api/clock.md +154 -0
- data/documentation/docs/api/console_message.md +85 -0
- data/documentation/docs/api/dialog.md +84 -0
- data/documentation/docs/api/download.md +111 -0
- data/documentation/docs/api/element_handle.md +694 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +42 -0
- data/documentation/docs/api/experimental/android_device.md +109 -0
- data/documentation/docs/api/experimental/android_input.md +43 -0
- data/documentation/docs/api/experimental/android_socket.md +7 -0
- data/documentation/docs/api/experimental/android_web_view.md +7 -0
- data/documentation/docs/api/file_chooser.md +53 -0
- data/documentation/docs/api/frame.md +1218 -0
- data/documentation/docs/api/frame_locator.md +348 -0
- data/documentation/docs/api/js_handle.md +121 -0
- data/documentation/docs/api/keyboard.md +170 -0
- data/documentation/docs/api/locator.md +1495 -0
- data/documentation/docs/api/locator_assertions.md +827 -0
- data/documentation/docs/api/mouse.md +86 -0
- data/documentation/docs/api/page.md +1946 -0
- data/documentation/docs/api/page_assertions.md +65 -0
- data/documentation/docs/api/playwright.md +66 -0
- data/documentation/docs/api/request.md +255 -0
- data/documentation/docs/api/response.md +176 -0
- data/documentation/docs/api/route.md +205 -0
- data/documentation/docs/api/selectors.md +63 -0
- data/documentation/docs/api/touchscreen.md +22 -0
- data/documentation/docs/api/tracing.md +129 -0
- data/documentation/docs/api/web_socket.md +51 -0
- data/documentation/docs/api/worker.md +83 -0
- data/documentation/docs/article/api_coverage.mdx +11 -0
- data/documentation/docs/article/getting_started.md +161 -0
- data/documentation/docs/article/guides/_category_.yml +3 -0
- data/documentation/docs/article/guides/download_playwright_driver.md +55 -0
- data/documentation/docs/article/guides/inspector.md +31 -0
- data/documentation/docs/article/guides/launch_browser.md +121 -0
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +112 -0
- data/documentation/docs/article/guides/rails_integration.md +278 -0
- data/documentation/docs/article/guides/rails_integration_with_null_driver.md +145 -0
- data/documentation/docs/article/guides/recording_video.md +79 -0
- data/documentation/docs/article/guides/rspec_integration.md +59 -0
- data/documentation/docs/article/guides/semi_automation.md +71 -0
- data/documentation/docs/article/guides/use_storage_state.md +78 -0
- data/documentation/docs/include/api_coverage.md +671 -0
- data/documentation/docusaurus.config.js +114 -0
- data/documentation/package.json +39 -0
- data/documentation/sidebars.js +15 -0
- data/documentation/src/components/HomepageFeatures.js +61 -0
- data/documentation/src/components/HomepageFeatures.module.css +13 -0
- data/documentation/src/css/custom.css +44 -0
- data/documentation/src/pages/index.js +49 -0
- data/documentation/src/pages/index.module.css +41 -0
- data/documentation/src/pages/markdown-page.md +7 -0
- data/documentation/static/.nojekyll +0 -0
- data/documentation/static/img/playwright-logo.svg +9 -0
- data/documentation/static/img/playwright-ruby-client.png +0 -0
- data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
- data/documentation/static/img/undraw_web_development.svg +1 -0
- data/documentation/static/img/undraw_windows.svg +1 -0
- data/documentation/yarn.lock +9005 -0
- data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
- data/lib/playwright/api_implementation.rb +18 -0
- data/lib/playwright/api_response_impl.rb +77 -0
- data/lib/playwright/channel.rb +62 -1
- data/lib/playwright/channel_owner.rb +70 -7
- data/lib/playwright/channel_owners/android.rb +16 -3
- data/lib/playwright/channel_owners/android_device.rb +22 -66
- data/lib/playwright/channel_owners/api_request_context.rb +247 -0
- data/lib/playwright/channel_owners/artifact.rb +40 -0
- data/lib/playwright/channel_owners/binding_call.rb +70 -0
- data/lib/playwright/channel_owners/browser.rb +114 -22
- data/lib/playwright/channel_owners/browser_context.rb +589 -15
- data/lib/playwright/channel_owners/browser_type.rb +90 -1
- data/lib/playwright/channel_owners/cdp_session.rb +19 -0
- data/lib/playwright/channel_owners/dialog.rb +32 -0
- data/lib/playwright/channel_owners/element_handle.rb +107 -43
- data/lib/playwright/channel_owners/fetch_request.rb +8 -0
- data/lib/playwright/channel_owners/frame.rb +334 -104
- data/lib/playwright/channel_owners/js_handle.rb +9 -13
- data/lib/playwright/channel_owners/local_utils.rb +82 -0
- data/lib/playwright/channel_owners/page.rb +778 -95
- data/lib/playwright/channel_owners/playwright.rb +25 -30
- data/lib/playwright/channel_owners/request.rb +120 -18
- data/lib/playwright/channel_owners/response.rb +113 -0
- data/lib/playwright/channel_owners/route.rb +181 -0
- data/lib/playwright/channel_owners/stream.rb +30 -0
- data/lib/playwright/channel_owners/tracing.rb +117 -0
- data/lib/playwright/channel_owners/web_socket.rb +96 -0
- data/lib/playwright/channel_owners/worker.rb +46 -0
- data/lib/playwright/channel_owners/writable_stream.rb +14 -0
- data/lib/playwright/clock_impl.rb +67 -0
- data/lib/playwright/connection.rb +111 -63
- data/lib/playwright/console_message_impl.rb +29 -0
- data/lib/playwright/download_impl.rb +32 -0
- data/lib/playwright/errors.rb +42 -5
- data/lib/playwright/event_emitter.rb +17 -3
- data/lib/playwright/event_emitter_proxy.rb +49 -0
- data/lib/playwright/events.rb +10 -5
- data/lib/playwright/file_chooser_impl.rb +24 -0
- data/lib/playwright/frame_locator_impl.rb +66 -0
- data/lib/playwright/har_router.rb +89 -0
- data/lib/playwright/http_headers.rb +14 -0
- data/lib/playwright/input_files.rb +102 -15
- data/lib/playwright/javascript/expression.rb +7 -11
- data/lib/playwright/javascript/regex.rb +23 -0
- data/lib/playwright/javascript/source_url.rb +16 -0
- data/lib/playwright/javascript/value_parser.rb +108 -19
- data/lib/playwright/javascript/value_serializer.rb +47 -8
- data/lib/playwright/javascript/visitor_info.rb +26 -0
- data/lib/playwright/javascript.rb +2 -10
- data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
- data/lib/playwright/locator_assertions_impl.rb +571 -0
- data/lib/playwright/locator_impl.rb +544 -0
- data/lib/playwright/locator_utils.rb +136 -0
- data/lib/playwright/mouse_impl.rb +57 -0
- data/lib/playwright/page_assertions_impl.rb +154 -0
- data/lib/playwright/playwright_api.rb +102 -30
- data/lib/playwright/raw_headers.rb +61 -0
- data/lib/playwright/route_handler.rb +78 -0
- data/lib/playwright/select_option_values.rb +34 -13
- data/lib/playwright/selectors_impl.rb +45 -0
- data/lib/playwright/test.rb +102 -0
- data/lib/playwright/timeout_settings.rb +9 -4
- data/lib/playwright/touchscreen_impl.rb +14 -0
- data/lib/playwright/transport.rb +61 -10
- data/lib/playwright/url_matcher.rb +24 -2
- data/lib/playwright/utils.rb +48 -13
- data/lib/playwright/version.rb +2 -1
- data/lib/playwright/video.rb +54 -0
- data/lib/playwright/waiter.rb +166 -0
- data/lib/playwright/web_socket_client.rb +167 -0
- data/lib/playwright/web_socket_transport.rb +116 -0
- data/lib/playwright.rb +188 -11
- data/lib/playwright_api/android.rb +46 -11
- data/lib/playwright_api/android_device.rb +182 -31
- data/lib/playwright_api/android_input.rb +22 -13
- data/lib/playwright_api/android_socket.rb +18 -0
- data/lib/playwright_api/android_web_view.rb +24 -0
- data/lib/playwright_api/api_request.rb +26 -0
- data/lib/playwright_api/api_request_context.rb +311 -0
- data/lib/playwright_api/api_response.rb +92 -0
- data/lib/playwright_api/browser.rb +116 -103
- data/lib/playwright_api/browser_context.rb +290 -389
- data/lib/playwright_api/browser_type.rb +96 -118
- data/lib/playwright_api/cdp_session.rb +36 -39
- data/lib/playwright_api/clock.rb +121 -0
- data/lib/playwright_api/console_message.rb +35 -19
- data/lib/playwright_api/dialog.rb +53 -50
- data/lib/playwright_api/download.rb +49 -43
- data/lib/playwright_api/element_handle.rb +354 -402
- data/lib/playwright_api/file_chooser.rb +15 -18
- data/lib/playwright_api/frame.rb +703 -603
- data/lib/playwright_api/frame_locator.rb +285 -0
- data/lib/playwright_api/js_handle.rb +50 -76
- data/lib/playwright_api/keyboard.rb +67 -146
- data/lib/playwright_api/locator.rb +1304 -0
- data/lib/playwright_api/locator_assertions.rb +704 -0
- data/lib/playwright_api/mouse.rb +23 -29
- data/lib/playwright_api/page.rb +1196 -1176
- data/lib/playwright_api/page_assertions.rb +60 -0
- data/lib/playwright_api/playwright.rb +54 -122
- data/lib/playwright_api/request.rb +112 -74
- data/lib/playwright_api/response.rb +92 -20
- data/lib/playwright_api/route.rb +152 -62
- data/lib/playwright_api/selectors.rb +47 -61
- data/lib/playwright_api/touchscreen.rb +8 -2
- data/lib/playwright_api/tracing.rb +128 -0
- data/lib/playwright_api/web_socket.rb +43 -5
- data/lib/playwright_api/worker.rb +74 -34
- data/playwright.gemspec +14 -9
- data/sig/playwright.rbs +658 -0
- metadata +216 -50
- data/docs/api_coverage.md +0 -354
- data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
- data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
- data/lib/playwright/channel_owners/console_message.rb +0 -21
- data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
- data/lib/playwright/channel_owners/selectors.rb +0 -4
- data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
- data/lib/playwright/input_type.rb +0 -19
- data/lib/playwright/input_types/mouse.rb +0 -4
- data/lib/playwright/input_types/touchscreen.rb +0 -4
- data/lib/playwright/javascript/function.rb +0 -67
- data/lib/playwright/wait_helper.rb +0 -73
- data/lib/playwright_api/accessibility.rb +0 -93
- data/lib/playwright_api/binding_call.rb +0 -23
- data/lib/playwright_api/chromium_browser_context.rb +0 -57
- data/lib/playwright_api/video.rb +0 -24
|
@@ -0,0 +1,1304 @@
|
|
|
1
|
+
module Playwright
|
|
2
|
+
#
|
|
3
|
+
# Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent
|
|
4
|
+
# a way to find element(s) on the page at any moment. A locator can be created with the [`method: Page.locator`] method.
|
|
5
|
+
#
|
|
6
|
+
# [Learn more about locators](../locators.md).
|
|
7
|
+
class Locator < PlaywrightApi
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements.
|
|
11
|
+
#
|
|
12
|
+
# **NOTE**: [`method: Locator.all`] does not wait for elements to match the locator, and instead immediately returns whatever is present in the page.
|
|
13
|
+
#
|
|
14
|
+
# When the list of elements changes dynamically, [`method: Locator.all`] will produce unpredictable and flaky results.
|
|
15
|
+
#
|
|
16
|
+
# When the list of elements is stable, but loaded dynamically, wait for the full list to finish loading before calling [`method: Locator.all`].
|
|
17
|
+
#
|
|
18
|
+
# **Usage**
|
|
19
|
+
#
|
|
20
|
+
# ```python sync
|
|
21
|
+
# for li in page.get_by_role('listitem').all():
|
|
22
|
+
# li.click();
|
|
23
|
+
# ```
|
|
24
|
+
def all
|
|
25
|
+
wrap_impl(@impl.all)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Returns an array of `node.innerText` values for all matching nodes.
|
|
30
|
+
#
|
|
31
|
+
# **NOTE**: If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with `useInnerText` option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
32
|
+
#
|
|
33
|
+
# **Usage**
|
|
34
|
+
#
|
|
35
|
+
# ```python sync
|
|
36
|
+
# texts = page.get_by_role("link").all_inner_texts()
|
|
37
|
+
# ```
|
|
38
|
+
def all_inner_texts
|
|
39
|
+
wrap_impl(@impl.all_inner_texts)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Returns an array of `node.textContent` values for all matching nodes.
|
|
44
|
+
#
|
|
45
|
+
# **NOTE**: If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
46
|
+
#
|
|
47
|
+
# **Usage**
|
|
48
|
+
#
|
|
49
|
+
# ```python sync
|
|
50
|
+
# texts = page.get_by_role("link").all_text_contents()
|
|
51
|
+
# ```
|
|
52
|
+
def all_text_contents
|
|
53
|
+
wrap_impl(@impl.all_text_contents)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Creates a locator that matches both this locator and the argument locator.
|
|
58
|
+
#
|
|
59
|
+
# **Usage**
|
|
60
|
+
#
|
|
61
|
+
# The following example finds a button with a specific title.
|
|
62
|
+
#
|
|
63
|
+
# ```python sync
|
|
64
|
+
# button = page.get_by_role("button").and_(page.get_by_title("Subscribe"))
|
|
65
|
+
# ```
|
|
66
|
+
def and(locator)
|
|
67
|
+
wrap_impl(@impl.and(unwrap_impl(locator)))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Captures the aria snapshot of the given element.
|
|
72
|
+
# Read more about [aria snapshots](../aria-snapshots.md) and [`method: LocatorAssertions.toMatchAriaSnapshot`] for the corresponding assertion.
|
|
73
|
+
#
|
|
74
|
+
# **Usage**
|
|
75
|
+
#
|
|
76
|
+
# ```python sync
|
|
77
|
+
# page.get_by_role("link").aria_snapshot()
|
|
78
|
+
# ```
|
|
79
|
+
#
|
|
80
|
+
# **Details**
|
|
81
|
+
#
|
|
82
|
+
# This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of the element and its children.
|
|
83
|
+
# The snapshot can be used to assert the state of the element in the test, or to compare it to state in the future.
|
|
84
|
+
#
|
|
85
|
+
# The ARIA snapshot is represented using [YAML](https://yaml.org/spec/1.2.2/) markup language:
|
|
86
|
+
# - The keys of the objects are the roles and optional accessible names of the elements.
|
|
87
|
+
# - The values are either text content or an array of child elements.
|
|
88
|
+
# - Generic static text can be represented with the `text` key.
|
|
89
|
+
#
|
|
90
|
+
# Below is the HTML markup and the respective ARIA snapshot:
|
|
91
|
+
#
|
|
92
|
+
# ```html
|
|
93
|
+
# <ul aria-label="Links">
|
|
94
|
+
# <li><a href="/">Home</a></li>
|
|
95
|
+
# <li><a href="/about">About</a></li>
|
|
96
|
+
# <ul>
|
|
97
|
+
# ```
|
|
98
|
+
#
|
|
99
|
+
# ```yml
|
|
100
|
+
# - list "Links":
|
|
101
|
+
# - listitem:
|
|
102
|
+
# - link "Home"
|
|
103
|
+
# - listitem:
|
|
104
|
+
# - link "About"
|
|
105
|
+
# ```
|
|
106
|
+
def aria_snapshot(timeout: nil)
|
|
107
|
+
wrap_impl(@impl.aria_snapshot(timeout: unwrap_impl(timeout)))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#
|
|
111
|
+
# Calls [blur](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur) on the element.
|
|
112
|
+
def blur(timeout: nil)
|
|
113
|
+
wrap_impl(@impl.blur(timeout: unwrap_impl(timeout)))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
#
|
|
117
|
+
# This method returns the bounding box of the element matching the locator, or `null` if the element is not visible. The bounding box is
|
|
118
|
+
# calculated relative to the main frame viewport - which is usually the same as the browser window.
|
|
119
|
+
#
|
|
120
|
+
# **Details**
|
|
121
|
+
#
|
|
122
|
+
# Scrolling affects the returned bounding box, similarly to
|
|
123
|
+
# [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
|
|
124
|
+
# means `x` and/or `y` may be negative.
|
|
125
|
+
#
|
|
126
|
+
# Elements from child frames return the bounding box relative to the main frame, unlike the
|
|
127
|
+
# [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
|
|
128
|
+
#
|
|
129
|
+
# Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
|
130
|
+
# snippet should click the center of the element.
|
|
131
|
+
#
|
|
132
|
+
# **Usage**
|
|
133
|
+
#
|
|
134
|
+
# ```python sync
|
|
135
|
+
# box = page.get_by_role("button").bounding_box()
|
|
136
|
+
# page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
|
|
137
|
+
# ```
|
|
138
|
+
def bounding_box(timeout: nil)
|
|
139
|
+
wrap_impl(@impl.bounding_box(timeout: unwrap_impl(timeout)))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
#
|
|
143
|
+
# Ensure that checkbox or radio element is checked.
|
|
144
|
+
#
|
|
145
|
+
# **Details**
|
|
146
|
+
#
|
|
147
|
+
# Performs the following steps:
|
|
148
|
+
# 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
|
|
149
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
150
|
+
# 1. Scroll the element into view if needed.
|
|
151
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
|
152
|
+
# 1. Ensure that the element is now checked. If not, this method throws.
|
|
153
|
+
#
|
|
154
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
155
|
+
#
|
|
156
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
157
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
158
|
+
#
|
|
159
|
+
# **Usage**
|
|
160
|
+
#
|
|
161
|
+
# ```python sync
|
|
162
|
+
# page.get_by_role("checkbox").check()
|
|
163
|
+
# ```
|
|
164
|
+
def check(
|
|
165
|
+
force: nil,
|
|
166
|
+
noWaitAfter: nil,
|
|
167
|
+
position: nil,
|
|
168
|
+
timeout: nil,
|
|
169
|
+
trial: nil)
|
|
170
|
+
wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
#
|
|
174
|
+
# Clear the input field.
|
|
175
|
+
#
|
|
176
|
+
# **Details**
|
|
177
|
+
#
|
|
178
|
+
# This method waits for [actionability](../actionability.md) checks, focuses the element, clears it and triggers an `input` event after clearing.
|
|
179
|
+
#
|
|
180
|
+
# 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 cleared instead.
|
|
181
|
+
#
|
|
182
|
+
# **Usage**
|
|
183
|
+
#
|
|
184
|
+
# ```python sync
|
|
185
|
+
# page.get_by_role("textbox").clear()
|
|
186
|
+
# ```
|
|
187
|
+
def clear(force: nil, noWaitAfter: nil, timeout: nil)
|
|
188
|
+
wrap_impl(@impl.clear(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# Click an element.
|
|
193
|
+
#
|
|
194
|
+
# **Details**
|
|
195
|
+
#
|
|
196
|
+
# This method clicks the element by performing the following steps:
|
|
197
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
198
|
+
# 1. Scroll the element into view if needed.
|
|
199
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
|
|
200
|
+
# 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
|
201
|
+
#
|
|
202
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
203
|
+
#
|
|
204
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
205
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
206
|
+
#
|
|
207
|
+
# **Usage**
|
|
208
|
+
#
|
|
209
|
+
# Click a button:
|
|
210
|
+
#
|
|
211
|
+
# ```python sync
|
|
212
|
+
# page.get_by_role("button").click()
|
|
213
|
+
# ```
|
|
214
|
+
#
|
|
215
|
+
# Shift-right-click at a specific position on a canvas:
|
|
216
|
+
#
|
|
217
|
+
# ```python sync
|
|
218
|
+
# page.locator("canvas").click(
|
|
219
|
+
# button="right", modifiers=["Shift"], position={"x": 23, "y": 32}
|
|
220
|
+
# )
|
|
221
|
+
# ```
|
|
222
|
+
def click(
|
|
223
|
+
button: nil,
|
|
224
|
+
clickCount: nil,
|
|
225
|
+
delay: nil,
|
|
226
|
+
force: nil,
|
|
227
|
+
modifiers: nil,
|
|
228
|
+
noWaitAfter: nil,
|
|
229
|
+
position: nil,
|
|
230
|
+
steps: nil,
|
|
231
|
+
timeout: nil,
|
|
232
|
+
trial: nil)
|
|
233
|
+
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), steps: unwrap_impl(steps), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
#
|
|
237
|
+
# Returns the number of elements matching the locator.
|
|
238
|
+
#
|
|
239
|
+
# **NOTE**: If you need to assert the number of elements on the page, prefer [`method: LocatorAssertions.toHaveCount`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
240
|
+
#
|
|
241
|
+
# **Usage**
|
|
242
|
+
#
|
|
243
|
+
# ```python sync
|
|
244
|
+
# count = page.get_by_role("listitem").count()
|
|
245
|
+
# ```
|
|
246
|
+
def count
|
|
247
|
+
wrap_impl(@impl.count)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
#
|
|
251
|
+
# Double-click an element.
|
|
252
|
+
#
|
|
253
|
+
# **Details**
|
|
254
|
+
#
|
|
255
|
+
# This method double clicks the element by performing the following steps:
|
|
256
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
257
|
+
# 1. Scroll the element into view if needed.
|
|
258
|
+
# 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
|
|
259
|
+
#
|
|
260
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
261
|
+
#
|
|
262
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
263
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
264
|
+
#
|
|
265
|
+
# **NOTE**: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
|
266
|
+
def dblclick(
|
|
267
|
+
button: nil,
|
|
268
|
+
delay: nil,
|
|
269
|
+
force: nil,
|
|
270
|
+
modifiers: nil,
|
|
271
|
+
noWaitAfter: nil,
|
|
272
|
+
position: nil,
|
|
273
|
+
steps: nil,
|
|
274
|
+
timeout: nil,
|
|
275
|
+
trial: nil)
|
|
276
|
+
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), steps: unwrap_impl(steps), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
#
|
|
280
|
+
# Describes the locator, description is used in the trace viewer and reports.
|
|
281
|
+
# Returns the locator pointing to the same element.
|
|
282
|
+
#
|
|
283
|
+
# **Usage**
|
|
284
|
+
#
|
|
285
|
+
# ```python sync
|
|
286
|
+
# button = page.get_by_test_id("btn-sub").describe("Subscribe button")
|
|
287
|
+
# button.click()
|
|
288
|
+
# ```
|
|
289
|
+
def describe(description)
|
|
290
|
+
wrap_impl(@impl.describe(unwrap_impl(description)))
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
#
|
|
294
|
+
# Returns locator description previously set with [`method: Locator.describe`]. Returns `null` if no custom description has been set.
|
|
295
|
+
#
|
|
296
|
+
# **Usage**
|
|
297
|
+
#
|
|
298
|
+
# ```python sync
|
|
299
|
+
# button = page.get_by_role("button").describe("Subscribe button")
|
|
300
|
+
# print(button.description()) # "Subscribe button"
|
|
301
|
+
#
|
|
302
|
+
# input = page.get_by_role("textbox")
|
|
303
|
+
# print(input.description()) # None
|
|
304
|
+
# ```
|
|
305
|
+
def description
|
|
306
|
+
wrap_impl(@impl.description)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
#
|
|
310
|
+
# Programmatically dispatch an event on the matching element.
|
|
311
|
+
#
|
|
312
|
+
# **Usage**
|
|
313
|
+
#
|
|
314
|
+
# ```python sync
|
|
315
|
+
# locator.dispatch_event("click")
|
|
316
|
+
# ```
|
|
317
|
+
#
|
|
318
|
+
# **Details**
|
|
319
|
+
#
|
|
320
|
+
# The snippet above dispatches the `click` event on the element. Regardless of the visibility state of the element, `click`
|
|
321
|
+
# is dispatched. This is equivalent to calling
|
|
322
|
+
# [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
|
323
|
+
#
|
|
324
|
+
# Under the hood, it creates an instance of an event based on the given `type`, initializes it with
|
|
325
|
+
# `eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
|
|
326
|
+
# default.
|
|
327
|
+
#
|
|
328
|
+
# Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
|
|
329
|
+
# properties:
|
|
330
|
+
# - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
|
|
331
|
+
# - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
|
|
332
|
+
# - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
|
|
333
|
+
# - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
|
|
334
|
+
# - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
|
|
335
|
+
# - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
|
|
336
|
+
# - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
|
|
337
|
+
# - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
|
|
338
|
+
# - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
|
|
339
|
+
# - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
|
|
340
|
+
#
|
|
341
|
+
# You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
|
|
342
|
+
#
|
|
343
|
+
# ```python sync
|
|
344
|
+
# data_transfer = page.evaluate_handle("new DataTransfer()")
|
|
345
|
+
# locator.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
|
|
346
|
+
# ```
|
|
347
|
+
def dispatch_event(type, eventInit: nil, timeout: nil)
|
|
348
|
+
wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
#
|
|
352
|
+
# Drag the source element towards the target element and drop it.
|
|
353
|
+
#
|
|
354
|
+
# **Details**
|
|
355
|
+
#
|
|
356
|
+
# This method drags the locator to another target locator or target position. It will
|
|
357
|
+
# first move to the source element, perform a `mousedown`, then move to the target
|
|
358
|
+
# element or position and perform a `mouseup`.
|
|
359
|
+
#
|
|
360
|
+
# **Usage**
|
|
361
|
+
#
|
|
362
|
+
# ```python sync
|
|
363
|
+
# source = page.locator("#source")
|
|
364
|
+
# target = page.locator("#target")
|
|
365
|
+
#
|
|
366
|
+
# source.drag_to(target)
|
|
367
|
+
# # or specify exact positions relative to the top-left corners of the elements:
|
|
368
|
+
# source.drag_to(
|
|
369
|
+
# target,
|
|
370
|
+
# source_position={"x": 34, "y": 7},
|
|
371
|
+
# target_position={"x": 10, "y": 20}
|
|
372
|
+
# )
|
|
373
|
+
# ```
|
|
374
|
+
def drag_to(
|
|
375
|
+
target,
|
|
376
|
+
force: nil,
|
|
377
|
+
noWaitAfter: nil,
|
|
378
|
+
sourcePosition: nil,
|
|
379
|
+
steps: nil,
|
|
380
|
+
targetPosition: nil,
|
|
381
|
+
timeout: nil,
|
|
382
|
+
trial: nil)
|
|
383
|
+
wrap_impl(@impl.drag_to(unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), sourcePosition: unwrap_impl(sourcePosition), steps: unwrap_impl(steps), targetPosition: unwrap_impl(targetPosition), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
#
|
|
387
|
+
# Resolves given locator to the first matching DOM element. If there are no matching elements, waits for one. If multiple elements match the locator, throws.
|
|
388
|
+
def element_handle(timeout: nil)
|
|
389
|
+
wrap_impl(@impl.element_handle(timeout: unwrap_impl(timeout)))
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
#
|
|
393
|
+
# Resolves given locator to all matching DOM elements. If there are no matching elements, returns an empty list.
|
|
394
|
+
def element_handles
|
|
395
|
+
wrap_impl(@impl.element_handles)
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
#
|
|
399
|
+
# Returns a `FrameLocator` object pointing to the same `iframe` as this locator.
|
|
400
|
+
#
|
|
401
|
+
# Useful when you have a `Locator` object obtained somewhere, and later on would like to interact with the content inside the frame.
|
|
402
|
+
#
|
|
403
|
+
# For a reverse operation, use [`method: FrameLocator.owner`].
|
|
404
|
+
#
|
|
405
|
+
# **Usage**
|
|
406
|
+
#
|
|
407
|
+
# ```python sync
|
|
408
|
+
# locator = page.locator("iframe[name=\"embedded\"]")
|
|
409
|
+
# # ...
|
|
410
|
+
# frame_locator = locator.content_frame
|
|
411
|
+
# frame_locator.get_by_role("button").click()
|
|
412
|
+
# ```
|
|
413
|
+
def content_frame
|
|
414
|
+
wrap_impl(@impl.content_frame)
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
#
|
|
418
|
+
# Execute JavaScript code in the page, taking the matching element as an argument.
|
|
419
|
+
#
|
|
420
|
+
# **Details**
|
|
421
|
+
#
|
|
422
|
+
# Returns the return value of `expression`, called with the matching element as a first argument, and `arg` as a second argument.
|
|
423
|
+
#
|
|
424
|
+
# If `expression` returns a [Promise], this method will wait for the promise to resolve and return its value.
|
|
425
|
+
#
|
|
426
|
+
# If `expression` throws or rejects, this method throws.
|
|
427
|
+
#
|
|
428
|
+
# **Usage**
|
|
429
|
+
#
|
|
430
|
+
# Passing argument to `expression`:
|
|
431
|
+
#
|
|
432
|
+
# ```python sync
|
|
433
|
+
# result = page.get_by_testid("myId").evaluate("(element, [x, y]) => element.textContent + ' ' + x * y", [7, 8])
|
|
434
|
+
# print(result) # prints "myId text 56"
|
|
435
|
+
# ```
|
|
436
|
+
def evaluate(expression, arg: nil, timeout: nil)
|
|
437
|
+
wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
#
|
|
441
|
+
# Execute JavaScript code in the page, taking all matching elements as an argument.
|
|
442
|
+
#
|
|
443
|
+
# **Details**
|
|
444
|
+
#
|
|
445
|
+
# Returns the return value of `expression`, called with an array of all matching elements as a first argument, and `arg` as a second argument.
|
|
446
|
+
#
|
|
447
|
+
# If `expression` returns a [Promise], this method will wait for the promise to resolve and return its value.
|
|
448
|
+
#
|
|
449
|
+
# If `expression` throws or rejects, this method throws.
|
|
450
|
+
#
|
|
451
|
+
# **Usage**
|
|
452
|
+
#
|
|
453
|
+
# ```python sync
|
|
454
|
+
# locator = page.locator("div")
|
|
455
|
+
# more_than_ten = locator.evaluate_all("(divs, min) => divs.length > min", 10)
|
|
456
|
+
# ```
|
|
457
|
+
def evaluate_all(expression, arg: nil)
|
|
458
|
+
wrap_impl(@impl.evaluate_all(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
#
|
|
462
|
+
# Execute JavaScript code in the page, taking the matching element as an argument, and return a `JSHandle` with the result.
|
|
463
|
+
#
|
|
464
|
+
# **Details**
|
|
465
|
+
#
|
|
466
|
+
# Returns the return value of `expression` as a`JSHandle`, called with the matching element as a first argument, and `arg` as a second argument.
|
|
467
|
+
#
|
|
468
|
+
# The only difference between [`method: Locator.evaluate`] and [`method: Locator.evaluateHandle`] is that [`method: Locator.evaluateHandle`] returns `JSHandle`.
|
|
469
|
+
#
|
|
470
|
+
# If `expression` returns a [Promise], this method will wait for the promise to resolve and return its value.
|
|
471
|
+
#
|
|
472
|
+
# If `expression` throws or rejects, this method throws.
|
|
473
|
+
#
|
|
474
|
+
# See [`method: Page.evaluateHandle`] for more details.
|
|
475
|
+
def evaluate_handle(expression, arg: nil, timeout: nil)
|
|
476
|
+
wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
#
|
|
480
|
+
# Set a value to the input field.
|
|
481
|
+
#
|
|
482
|
+
# **Usage**
|
|
483
|
+
#
|
|
484
|
+
# ```python sync
|
|
485
|
+
# page.get_by_role("textbox").fill("example value")
|
|
486
|
+
# ```
|
|
487
|
+
#
|
|
488
|
+
# **Details**
|
|
489
|
+
#
|
|
490
|
+
# This method 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.
|
|
491
|
+
#
|
|
492
|
+
# 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.
|
|
493
|
+
#
|
|
494
|
+
# To send fine-grained keyboard events, use [`method: Locator.pressSequentially`].
|
|
495
|
+
def fill(value, force: nil, noWaitAfter: nil, timeout: nil)
|
|
496
|
+
wrap_impl(@impl.fill(unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
#
|
|
500
|
+
# This method narrows existing locator according to the options, for example filters by text.
|
|
501
|
+
# It can be chained to filter multiple times.
|
|
502
|
+
#
|
|
503
|
+
# **Usage**
|
|
504
|
+
#
|
|
505
|
+
# ```python sync
|
|
506
|
+
# row_locator = page.locator("tr")
|
|
507
|
+
# # ...
|
|
508
|
+
# row_locator.filter(has_text="text in column 1").filter(
|
|
509
|
+
# has=page.get_by_role("button", name="column 2 button")
|
|
510
|
+
# ).screenshot()
|
|
511
|
+
# ```
|
|
512
|
+
def filter(
|
|
513
|
+
has: nil,
|
|
514
|
+
hasNot: nil,
|
|
515
|
+
hasNotText: nil,
|
|
516
|
+
hasText: nil,
|
|
517
|
+
visible: nil)
|
|
518
|
+
wrap_impl(@impl.filter(has: unwrap_impl(has), hasNot: unwrap_impl(hasNot), hasNotText: unwrap_impl(hasNotText), hasText: unwrap_impl(hasText), visible: unwrap_impl(visible)))
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
#
|
|
522
|
+
# Returns locator to the first matching element.
|
|
523
|
+
def first
|
|
524
|
+
wrap_impl(@impl.first)
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
#
|
|
528
|
+
# Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the matching element.
|
|
529
|
+
def focus(timeout: nil)
|
|
530
|
+
wrap_impl(@impl.focus(timeout: unwrap_impl(timeout)))
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
#
|
|
534
|
+
# When working with iframes, you can create a frame locator that will enter the iframe and allow locating elements
|
|
535
|
+
# in that iframe:
|
|
536
|
+
#
|
|
537
|
+
# **Usage**
|
|
538
|
+
#
|
|
539
|
+
# ```python sync
|
|
540
|
+
# locator = page.frame_locator("iframe").get_by_text("Submit")
|
|
541
|
+
# locator.click()
|
|
542
|
+
# ```
|
|
543
|
+
def frame_locator(selector)
|
|
544
|
+
wrap_impl(@impl.frame_locator(unwrap_impl(selector)))
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
#
|
|
548
|
+
# Returns the matching element's attribute value.
|
|
549
|
+
#
|
|
550
|
+
# **NOTE**: If you need to assert an element's attribute, prefer [`method: LocatorAssertions.toHaveAttribute`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
551
|
+
def get_attribute(name, timeout: nil)
|
|
552
|
+
wrap_impl(@impl.get_attribute(unwrap_impl(name), timeout: unwrap_impl(timeout)))
|
|
553
|
+
end
|
|
554
|
+
alias_method :[], :get_attribute
|
|
555
|
+
|
|
556
|
+
#
|
|
557
|
+
# Allows locating elements by their alt text.
|
|
558
|
+
#
|
|
559
|
+
# **Usage**
|
|
560
|
+
#
|
|
561
|
+
# For example, this method will find the image by alt text "Playwright logo":
|
|
562
|
+
#
|
|
563
|
+
# ```html
|
|
564
|
+
# <img alt='Playwright logo'>
|
|
565
|
+
# ```
|
|
566
|
+
#
|
|
567
|
+
# ```python sync
|
|
568
|
+
# page.get_by_alt_text("Playwright logo").click()
|
|
569
|
+
# ```
|
|
570
|
+
def get_by_alt_text(text, exact: nil)
|
|
571
|
+
wrap_impl(@impl.get_by_alt_text(unwrap_impl(text), exact: unwrap_impl(exact)))
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
#
|
|
575
|
+
# Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the `aria-label` attribute.
|
|
576
|
+
#
|
|
577
|
+
# **Usage**
|
|
578
|
+
#
|
|
579
|
+
# For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
|
580
|
+
#
|
|
581
|
+
# ```html
|
|
582
|
+
# <input aria-label="Username">
|
|
583
|
+
# <label for="password-input">Password:</label>
|
|
584
|
+
# <input id="password-input">
|
|
585
|
+
# ```
|
|
586
|
+
#
|
|
587
|
+
# ```python sync
|
|
588
|
+
# page.get_by_label("Username").fill("john")
|
|
589
|
+
# page.get_by_label("Password").fill("secret")
|
|
590
|
+
# ```
|
|
591
|
+
def get_by_label(text, exact: nil)
|
|
592
|
+
wrap_impl(@impl.get_by_label(unwrap_impl(text), exact: unwrap_impl(exact)))
|
|
593
|
+
end
|
|
594
|
+
|
|
595
|
+
#
|
|
596
|
+
# Allows locating input elements by the placeholder text.
|
|
597
|
+
#
|
|
598
|
+
# **Usage**
|
|
599
|
+
#
|
|
600
|
+
# For example, consider the following DOM structure.
|
|
601
|
+
#
|
|
602
|
+
# ```html
|
|
603
|
+
# <input type="email" placeholder="name@example.com" />
|
|
604
|
+
# ```
|
|
605
|
+
#
|
|
606
|
+
# You can fill the input after locating it by the placeholder text:
|
|
607
|
+
#
|
|
608
|
+
# ```python sync
|
|
609
|
+
# page.get_by_placeholder("name@example.com").fill("playwright@microsoft.com")
|
|
610
|
+
# ```
|
|
611
|
+
def get_by_placeholder(text, exact: nil)
|
|
612
|
+
wrap_impl(@impl.get_by_placeholder(unwrap_impl(text), exact: unwrap_impl(exact)))
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
#
|
|
616
|
+
# 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).
|
|
617
|
+
#
|
|
618
|
+
# **Usage**
|
|
619
|
+
#
|
|
620
|
+
# Consider the following DOM structure.
|
|
621
|
+
#
|
|
622
|
+
# ```html
|
|
623
|
+
# <h3>Sign up</h3>
|
|
624
|
+
# <label>
|
|
625
|
+
# <input type="checkbox" /> Subscribe
|
|
626
|
+
# </label>
|
|
627
|
+
# <br/>
|
|
628
|
+
# <button>Submit</button>
|
|
629
|
+
# ```
|
|
630
|
+
#
|
|
631
|
+
# You can locate each element by it's implicit role:
|
|
632
|
+
#
|
|
633
|
+
# ```python sync
|
|
634
|
+
# expect(page.get_by_role("heading", name="Sign up")).to_be_visible()
|
|
635
|
+
#
|
|
636
|
+
# page.get_by_role("checkbox", name="Subscribe").check()
|
|
637
|
+
#
|
|
638
|
+
# page.get_by_role("button", name=re.compile("submit", re.IGNORECASE)).click()
|
|
639
|
+
# ```
|
|
640
|
+
#
|
|
641
|
+
# **Details**
|
|
642
|
+
#
|
|
643
|
+
# Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
|
644
|
+
#
|
|
645
|
+
# 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.
|
|
646
|
+
def get_by_role(
|
|
647
|
+
role,
|
|
648
|
+
checked: nil,
|
|
649
|
+
disabled: nil,
|
|
650
|
+
exact: nil,
|
|
651
|
+
expanded: nil,
|
|
652
|
+
includeHidden: nil,
|
|
653
|
+
level: nil,
|
|
654
|
+
name: nil,
|
|
655
|
+
pressed: nil,
|
|
656
|
+
selected: nil)
|
|
657
|
+
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)))
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
#
|
|
661
|
+
# Locate element by the test id.
|
|
662
|
+
#
|
|
663
|
+
# **Usage**
|
|
664
|
+
#
|
|
665
|
+
# Consider the following DOM structure.
|
|
666
|
+
#
|
|
667
|
+
# ```html
|
|
668
|
+
# <button data-testid="directions">Itinéraire</button>
|
|
669
|
+
# ```
|
|
670
|
+
#
|
|
671
|
+
# You can locate the element by it's test id:
|
|
672
|
+
#
|
|
673
|
+
# ```python sync
|
|
674
|
+
# page.get_by_test_id("directions").click()
|
|
675
|
+
# ```
|
|
676
|
+
#
|
|
677
|
+
# **Details**
|
|
678
|
+
#
|
|
679
|
+
# 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.
|
|
680
|
+
def get_by_test_id(testId)
|
|
681
|
+
wrap_impl(@impl.get_by_test_id(unwrap_impl(testId)))
|
|
682
|
+
end
|
|
683
|
+
alias_method :get_by_testid, :get_by_test_id
|
|
684
|
+
|
|
685
|
+
#
|
|
686
|
+
# Allows locating elements that contain given text.
|
|
687
|
+
#
|
|
688
|
+
# See also [`method: Locator.filter`] that allows to match by another criteria, like an accessible role, and then filter by the text content.
|
|
689
|
+
#
|
|
690
|
+
# **Usage**
|
|
691
|
+
#
|
|
692
|
+
# Consider the following DOM structure:
|
|
693
|
+
#
|
|
694
|
+
# ```html
|
|
695
|
+
# <div>Hello <span>world</span></div>
|
|
696
|
+
# <div>Hello</div>
|
|
697
|
+
# ```
|
|
698
|
+
#
|
|
699
|
+
# You can locate by text substring, exact string, or a regular expression:
|
|
700
|
+
#
|
|
701
|
+
# ```python sync
|
|
702
|
+
# # Matches <span>
|
|
703
|
+
# page.get_by_text("world")
|
|
704
|
+
#
|
|
705
|
+
# # Matches first <div>
|
|
706
|
+
# page.get_by_text("Hello world")
|
|
707
|
+
#
|
|
708
|
+
# # Matches second <div>
|
|
709
|
+
# page.get_by_text("Hello", exact=True)
|
|
710
|
+
#
|
|
711
|
+
# # Matches both <div>s
|
|
712
|
+
# page.get_by_text(re.compile("Hello"))
|
|
713
|
+
#
|
|
714
|
+
# # Matches second <div>
|
|
715
|
+
# page.get_by_text(re.compile("^hello$", re.IGNORECASE))
|
|
716
|
+
# ```
|
|
717
|
+
#
|
|
718
|
+
# **Details**
|
|
719
|
+
#
|
|
720
|
+
# 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.
|
|
721
|
+
#
|
|
722
|
+
# 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">`.
|
|
723
|
+
def get_by_text(text, exact: nil)
|
|
724
|
+
wrap_impl(@impl.get_by_text(unwrap_impl(text), exact: unwrap_impl(exact)))
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
#
|
|
728
|
+
# Allows locating elements by their title attribute.
|
|
729
|
+
#
|
|
730
|
+
# **Usage**
|
|
731
|
+
#
|
|
732
|
+
# Consider the following DOM structure.
|
|
733
|
+
#
|
|
734
|
+
# ```html
|
|
735
|
+
# <span title='Issues count'>25 issues</span>
|
|
736
|
+
# ```
|
|
737
|
+
#
|
|
738
|
+
# You can check the issues count after locating it by the title text:
|
|
739
|
+
#
|
|
740
|
+
# ```python sync
|
|
741
|
+
# expect(page.get_by_title("Issues count")).to_have_text("25 issues")
|
|
742
|
+
# ```
|
|
743
|
+
def get_by_title(text, exact: nil)
|
|
744
|
+
wrap_impl(@impl.get_by_title(unwrap_impl(text), exact: unwrap_impl(exact)))
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
#
|
|
748
|
+
# Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses [`method: Locator.highlight`].
|
|
749
|
+
def highlight
|
|
750
|
+
wrap_impl(@impl.highlight)
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
#
|
|
754
|
+
# Hover over the matching element.
|
|
755
|
+
#
|
|
756
|
+
# **Usage**
|
|
757
|
+
#
|
|
758
|
+
# ```python sync
|
|
759
|
+
# page.get_by_role("link").hover()
|
|
760
|
+
# ```
|
|
761
|
+
#
|
|
762
|
+
# **Details**
|
|
763
|
+
#
|
|
764
|
+
# This method hovers over the element by performing the following steps:
|
|
765
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
766
|
+
# 1. Scroll the element into view if needed.
|
|
767
|
+
# 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
|
|
768
|
+
#
|
|
769
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
770
|
+
#
|
|
771
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
772
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
773
|
+
def hover(
|
|
774
|
+
force: nil,
|
|
775
|
+
modifiers: nil,
|
|
776
|
+
noWaitAfter: nil,
|
|
777
|
+
position: nil,
|
|
778
|
+
timeout: nil,
|
|
779
|
+
trial: nil)
|
|
780
|
+
wrap_impl(@impl.hover(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
#
|
|
784
|
+
# Returns the [`element.innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML).
|
|
785
|
+
def inner_html(timeout: nil)
|
|
786
|
+
wrap_impl(@impl.inner_html(timeout: unwrap_impl(timeout)))
|
|
787
|
+
end
|
|
788
|
+
|
|
789
|
+
#
|
|
790
|
+
# Returns the [`element.innerText`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText).
|
|
791
|
+
#
|
|
792
|
+
# **NOTE**: If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with `useInnerText` option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
793
|
+
def inner_text(timeout: nil)
|
|
794
|
+
wrap_impl(@impl.inner_text(timeout: unwrap_impl(timeout)))
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
#
|
|
798
|
+
# Returns the value for the matching `<input>` or `<textarea>` or `<select>` element.
|
|
799
|
+
#
|
|
800
|
+
# **NOTE**: If you need to assert input value, prefer [`method: LocatorAssertions.toHaveValue`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
801
|
+
#
|
|
802
|
+
# **Usage**
|
|
803
|
+
#
|
|
804
|
+
# ```python sync
|
|
805
|
+
# value = page.get_by_role("textbox").input_value()
|
|
806
|
+
# ```
|
|
807
|
+
#
|
|
808
|
+
# **Details**
|
|
809
|
+
#
|
|
810
|
+
# Throws elements that are not an input, textarea or a select. 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.
|
|
811
|
+
def input_value(timeout: nil)
|
|
812
|
+
wrap_impl(@impl.input_value(timeout: unwrap_impl(timeout)))
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
#
|
|
816
|
+
# Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
|
817
|
+
#
|
|
818
|
+
# **NOTE**: If you need to assert that checkbox is checked, prefer [`method: LocatorAssertions.toBeChecked`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
819
|
+
#
|
|
820
|
+
# **Usage**
|
|
821
|
+
#
|
|
822
|
+
# ```python sync
|
|
823
|
+
# checked = page.get_by_role("checkbox").is_checked()
|
|
824
|
+
# ```
|
|
825
|
+
def checked?(timeout: nil)
|
|
826
|
+
wrap_impl(@impl.checked?(timeout: unwrap_impl(timeout)))
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
#
|
|
830
|
+
# Returns whether the element is disabled, the opposite of [enabled](../actionability.md#enabled).
|
|
831
|
+
#
|
|
832
|
+
# **NOTE**: If you need to assert that an element is disabled, prefer [`method: LocatorAssertions.toBeDisabled`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
833
|
+
#
|
|
834
|
+
# **Usage**
|
|
835
|
+
#
|
|
836
|
+
# ```python sync
|
|
837
|
+
# disabled = page.get_by_role("button").is_disabled()
|
|
838
|
+
# ```
|
|
839
|
+
def disabled?(timeout: nil)
|
|
840
|
+
wrap_impl(@impl.disabled?(timeout: unwrap_impl(timeout)))
|
|
841
|
+
end
|
|
842
|
+
|
|
843
|
+
#
|
|
844
|
+
# Returns whether the element is [editable](../actionability.md#editable). If the target element is not an `<input>`, `<textarea>`, `<select>`, `[contenteditable]` and does not have a role allowing `[aria-readonly]`, this method throws an error.
|
|
845
|
+
#
|
|
846
|
+
# **NOTE**: If you need to assert that an element is editable, prefer [`method: LocatorAssertions.toBeEditable`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
847
|
+
#
|
|
848
|
+
# **Usage**
|
|
849
|
+
#
|
|
850
|
+
# ```python sync
|
|
851
|
+
# editable = page.get_by_role("textbox").is_editable()
|
|
852
|
+
# ```
|
|
853
|
+
def editable?(timeout: nil)
|
|
854
|
+
wrap_impl(@impl.editable?(timeout: unwrap_impl(timeout)))
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
#
|
|
858
|
+
# Returns whether the element is [enabled](../actionability.md#enabled).
|
|
859
|
+
#
|
|
860
|
+
# **NOTE**: If you need to assert that an element is enabled, prefer [`method: LocatorAssertions.toBeEnabled`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
861
|
+
#
|
|
862
|
+
# **Usage**
|
|
863
|
+
#
|
|
864
|
+
# ```python sync
|
|
865
|
+
# enabled = page.get_by_role("button").is_enabled()
|
|
866
|
+
# ```
|
|
867
|
+
def enabled?(timeout: nil)
|
|
868
|
+
wrap_impl(@impl.enabled?(timeout: unwrap_impl(timeout)))
|
|
869
|
+
end
|
|
870
|
+
|
|
871
|
+
#
|
|
872
|
+
# Returns whether the element is hidden, the opposite of [visible](../actionability.md#visible).
|
|
873
|
+
#
|
|
874
|
+
# **NOTE**: If you need to assert that element is hidden, prefer [`method: LocatorAssertions.toBeHidden`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
875
|
+
#
|
|
876
|
+
# **Usage**
|
|
877
|
+
#
|
|
878
|
+
# ```python sync
|
|
879
|
+
# hidden = page.get_by_role("button").is_hidden()
|
|
880
|
+
# ```
|
|
881
|
+
def hidden?(timeout: nil)
|
|
882
|
+
wrap_impl(@impl.hidden?(timeout: unwrap_impl(timeout)))
|
|
883
|
+
end
|
|
884
|
+
|
|
885
|
+
#
|
|
886
|
+
# Returns whether the element is [visible](../actionability.md#visible).
|
|
887
|
+
#
|
|
888
|
+
# **NOTE**: If you need to assert that element is visible, prefer [`method: LocatorAssertions.toBeVisible`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
889
|
+
#
|
|
890
|
+
# **Usage**
|
|
891
|
+
#
|
|
892
|
+
# ```python sync
|
|
893
|
+
# visible = page.get_by_role("button").is_visible()
|
|
894
|
+
# ```
|
|
895
|
+
def visible?(timeout: nil)
|
|
896
|
+
wrap_impl(@impl.visible?(timeout: unwrap_impl(timeout)))
|
|
897
|
+
end
|
|
898
|
+
|
|
899
|
+
#
|
|
900
|
+
# Returns locator to the last matching element.
|
|
901
|
+
#
|
|
902
|
+
# **Usage**
|
|
903
|
+
#
|
|
904
|
+
# ```python sync
|
|
905
|
+
# banana = page.get_by_role("listitem").last
|
|
906
|
+
# ```
|
|
907
|
+
def last
|
|
908
|
+
wrap_impl(@impl.last)
|
|
909
|
+
end
|
|
910
|
+
|
|
911
|
+
#
|
|
912
|
+
# The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options, similar to [`method: Locator.filter`] method.
|
|
913
|
+
#
|
|
914
|
+
# [Learn more about locators](../locators.md).
|
|
915
|
+
def locator(
|
|
916
|
+
selectorOrLocator,
|
|
917
|
+
has: nil,
|
|
918
|
+
hasNot: nil,
|
|
919
|
+
hasNotText: nil,
|
|
920
|
+
hasText: nil)
|
|
921
|
+
wrap_impl(@impl.locator(unwrap_impl(selectorOrLocator), has: unwrap_impl(has), hasNot: unwrap_impl(hasNot), hasNotText: unwrap_impl(hasNotText), hasText: unwrap_impl(hasText)))
|
|
922
|
+
end
|
|
923
|
+
|
|
924
|
+
#
|
|
925
|
+
# Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element.
|
|
926
|
+
#
|
|
927
|
+
# **Usage**
|
|
928
|
+
#
|
|
929
|
+
# ```python sync
|
|
930
|
+
# banana = page.get_by_role("listitem").nth(2)
|
|
931
|
+
# ```
|
|
932
|
+
def nth(index)
|
|
933
|
+
wrap_impl(@impl.nth(unwrap_impl(index)))
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
#
|
|
937
|
+
# Creates a locator matching all elements that match one or both of the two locators.
|
|
938
|
+
#
|
|
939
|
+
# Note that when both locators match something, the resulting locator will have multiple matches, potentially causing a [locator strictness](../locators.md#strictness) violation.
|
|
940
|
+
#
|
|
941
|
+
# **Usage**
|
|
942
|
+
#
|
|
943
|
+
# Consider a scenario where you'd like to click on a "New email" button, but sometimes a security settings dialog shows up instead. In this case, you can wait for either a "New email" button, or a dialog and act accordingly.
|
|
944
|
+
#
|
|
945
|
+
# **NOTE**: If both "New email" button and security dialog appear on screen, the "or" locator will match both of them,
|
|
946
|
+
# possibly throwing the ["strict mode violation" error](../locators.md#strictness). In this case, you can use [`method: Locator.first`] to only match one of them.
|
|
947
|
+
#
|
|
948
|
+
# ```python sync
|
|
949
|
+
# new_email = page.get_by_role("button", name="New")
|
|
950
|
+
# dialog = page.get_by_text("Confirm security settings")
|
|
951
|
+
# expect(new_email.or_(dialog).first).to_be_visible()
|
|
952
|
+
# if (dialog.is_visible()):
|
|
953
|
+
# page.get_by_role("button", name="Dismiss").click()
|
|
954
|
+
# new_email.click()
|
|
955
|
+
# ```
|
|
956
|
+
def or(locator)
|
|
957
|
+
wrap_impl(@impl.or(unwrap_impl(locator)))
|
|
958
|
+
end
|
|
959
|
+
|
|
960
|
+
#
|
|
961
|
+
# A page this locator belongs to.
|
|
962
|
+
def page
|
|
963
|
+
wrap_impl(@impl.page)
|
|
964
|
+
end
|
|
965
|
+
|
|
966
|
+
#
|
|
967
|
+
# Focuses the matching element and presses a combination of the keys.
|
|
968
|
+
#
|
|
969
|
+
# **Usage**
|
|
970
|
+
#
|
|
971
|
+
# ```python sync
|
|
972
|
+
# page.get_by_role("textbox").press("Backspace")
|
|
973
|
+
# ```
|
|
974
|
+
#
|
|
975
|
+
# **Details**
|
|
976
|
+
#
|
|
977
|
+
# Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
|
978
|
+
#
|
|
979
|
+
# `key` can specify the intended
|
|
980
|
+
# [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
|
|
981
|
+
# generate the text for. A superset of the `key` values can be found
|
|
982
|
+
# [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
|
983
|
+
#
|
|
984
|
+
# `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
|
985
|
+
# `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
|
986
|
+
#
|
|
987
|
+
# Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, `ControlOrMeta`.
|
|
988
|
+
# `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS.
|
|
989
|
+
#
|
|
990
|
+
# Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
|
991
|
+
#
|
|
992
|
+
# If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
|
|
993
|
+
# respective texts.
|
|
994
|
+
#
|
|
995
|
+
# Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When specified with the
|
|
996
|
+
# modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
|
997
|
+
def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
|
|
998
|
+
wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
999
|
+
end
|
|
1000
|
+
|
|
1001
|
+
#
|
|
1002
|
+
# **NOTE**: In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page.
|
|
1003
|
+
#
|
|
1004
|
+
# Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
|
1005
|
+
#
|
|
1006
|
+
# To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
|
|
1007
|
+
#
|
|
1008
|
+
# **Usage**
|
|
1009
|
+
#
|
|
1010
|
+
# ```python sync
|
|
1011
|
+
# locator.press_sequentially("hello") # types instantly
|
|
1012
|
+
# locator.press_sequentially("world", delay=100) # types slower, like a user
|
|
1013
|
+
# ```
|
|
1014
|
+
#
|
|
1015
|
+
# An example of typing into a text field and then submitting the form:
|
|
1016
|
+
#
|
|
1017
|
+
# ```python sync
|
|
1018
|
+
# locator = page.get_by_label("Password")
|
|
1019
|
+
# locator.press_sequentially("my password")
|
|
1020
|
+
# locator.press("Enter")
|
|
1021
|
+
# ```
|
|
1022
|
+
def press_sequentially(text, delay: nil, noWaitAfter: nil, timeout: nil)
|
|
1023
|
+
wrap_impl(@impl.press_sequentially(unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
1024
|
+
end
|
|
1025
|
+
|
|
1026
|
+
#
|
|
1027
|
+
# Take a screenshot of the element matching the locator.
|
|
1028
|
+
#
|
|
1029
|
+
# **Usage**
|
|
1030
|
+
#
|
|
1031
|
+
# ```python sync
|
|
1032
|
+
# page.get_by_role("link").screenshot()
|
|
1033
|
+
# ```
|
|
1034
|
+
#
|
|
1035
|
+
# Disable animations and save screenshot to a file:
|
|
1036
|
+
#
|
|
1037
|
+
# ```python sync
|
|
1038
|
+
# page.get_by_role("link").screenshot(animations="disabled", path="link.png")
|
|
1039
|
+
# ```
|
|
1040
|
+
#
|
|
1041
|
+
# **Details**
|
|
1042
|
+
#
|
|
1043
|
+
# This method captures a screenshot of the page, clipped to the size and position of a particular element matching the locator. If the element is covered by other elements, it will not be actually visible on the screenshot. If the element is a scrollable container, only the currently scrolled content will be visible on the screenshot.
|
|
1044
|
+
#
|
|
1045
|
+
# This method waits for the [actionability](../actionability.md) checks, then scrolls element into view before taking a
|
|
1046
|
+
# screenshot. If the element is detached from DOM, the method throws an error.
|
|
1047
|
+
#
|
|
1048
|
+
# Returns the buffer with the captured screenshot.
|
|
1049
|
+
def screenshot(
|
|
1050
|
+
animations: nil,
|
|
1051
|
+
caret: nil,
|
|
1052
|
+
mask: nil,
|
|
1053
|
+
maskColor: nil,
|
|
1054
|
+
omitBackground: nil,
|
|
1055
|
+
path: nil,
|
|
1056
|
+
quality: nil,
|
|
1057
|
+
scale: nil,
|
|
1058
|
+
style: nil,
|
|
1059
|
+
timeout: nil,
|
|
1060
|
+
type: nil)
|
|
1061
|
+
wrap_impl(@impl.screenshot(animations: unwrap_impl(animations), caret: unwrap_impl(caret), mask: unwrap_impl(mask), maskColor: unwrap_impl(maskColor), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), scale: unwrap_impl(scale), style: unwrap_impl(style), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
|
|
1062
|
+
end
|
|
1063
|
+
|
|
1064
|
+
#
|
|
1065
|
+
# This method waits for [actionability](../actionability.md) checks, then tries to scroll element into view, unless it is
|
|
1066
|
+
# completely visible as defined by
|
|
1067
|
+
# [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
|
|
1068
|
+
#
|
|
1069
|
+
# See [scrolling](../input.md#scrolling) for alternative ways to scroll.
|
|
1070
|
+
def scroll_into_view_if_needed(timeout: nil)
|
|
1071
|
+
wrap_impl(@impl.scroll_into_view_if_needed(timeout: unwrap_impl(timeout)))
|
|
1072
|
+
end
|
|
1073
|
+
|
|
1074
|
+
#
|
|
1075
|
+
# Selects option or options in `<select>`.
|
|
1076
|
+
#
|
|
1077
|
+
# **Details**
|
|
1078
|
+
#
|
|
1079
|
+
# This method waits for [actionability](../actionability.md) checks, waits until all specified options are present in the `<select>` element and selects these options.
|
|
1080
|
+
#
|
|
1081
|
+
# 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.
|
|
1082
|
+
#
|
|
1083
|
+
# Returns the array of option values that have been successfully selected.
|
|
1084
|
+
#
|
|
1085
|
+
# Triggers a `change` and `input` event once all the provided options have been selected.
|
|
1086
|
+
#
|
|
1087
|
+
# **Usage**
|
|
1088
|
+
#
|
|
1089
|
+
# ```html
|
|
1090
|
+
# <select multiple>
|
|
1091
|
+
# <option value="red">Red</option>
|
|
1092
|
+
# <option value="green">Green</option>
|
|
1093
|
+
# <option value="blue">Blue</option>
|
|
1094
|
+
# </select>
|
|
1095
|
+
# ```
|
|
1096
|
+
#
|
|
1097
|
+
# ```python sync
|
|
1098
|
+
# # single selection matching the value or label
|
|
1099
|
+
# element.select_option("blue")
|
|
1100
|
+
# # single selection matching the label
|
|
1101
|
+
# element.select_option(label="blue")
|
|
1102
|
+
# # multiple selection for blue, red and second option
|
|
1103
|
+
# element.select_option(value=["red", "green", "blue"])
|
|
1104
|
+
# ```
|
|
1105
|
+
def select_option(
|
|
1106
|
+
element: nil,
|
|
1107
|
+
index: nil,
|
|
1108
|
+
value: nil,
|
|
1109
|
+
label: nil,
|
|
1110
|
+
force: nil,
|
|
1111
|
+
noWaitAfter: nil,
|
|
1112
|
+
timeout: nil)
|
|
1113
|
+
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)))
|
|
1114
|
+
end
|
|
1115
|
+
|
|
1116
|
+
#
|
|
1117
|
+
# This method waits for [actionability](../actionability.md) checks, then focuses the element and selects all its text
|
|
1118
|
+
# content.
|
|
1119
|
+
#
|
|
1120
|
+
# If the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), focuses and selects text in the control instead.
|
|
1121
|
+
def select_text(force: nil, timeout: nil)
|
|
1122
|
+
wrap_impl(@impl.select_text(force: unwrap_impl(force), timeout: unwrap_impl(timeout)))
|
|
1123
|
+
end
|
|
1124
|
+
|
|
1125
|
+
#
|
|
1126
|
+
# Set the state of a checkbox or a radio element.
|
|
1127
|
+
#
|
|
1128
|
+
# **Usage**
|
|
1129
|
+
#
|
|
1130
|
+
# ```python sync
|
|
1131
|
+
# page.get_by_role("checkbox").set_checked(True)
|
|
1132
|
+
# ```
|
|
1133
|
+
#
|
|
1134
|
+
# **Details**
|
|
1135
|
+
#
|
|
1136
|
+
# This method checks or unchecks an element by performing the following steps:
|
|
1137
|
+
# 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
|
|
1138
|
+
# 1. If the element already has the right checked state, this method returns immediately.
|
|
1139
|
+
# 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.
|
|
1140
|
+
# 1. Scroll the element into view if needed.
|
|
1141
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
|
1142
|
+
# 1. Ensure that the element is now checked or unchecked. If not, this method throws.
|
|
1143
|
+
#
|
|
1144
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
1145
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
1146
|
+
def set_checked(
|
|
1147
|
+
checked,
|
|
1148
|
+
force: nil,
|
|
1149
|
+
noWaitAfter: nil,
|
|
1150
|
+
position: nil,
|
|
1151
|
+
timeout: nil,
|
|
1152
|
+
trial: nil)
|
|
1153
|
+
wrap_impl(@impl.set_checked(unwrap_impl(checked), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
1154
|
+
end
|
|
1155
|
+
alias_method :checked=, :set_checked
|
|
1156
|
+
|
|
1157
|
+
#
|
|
1158
|
+
# Upload file or multiple files into `<input type=file>`.
|
|
1159
|
+
# For inputs with a `[webkitdirectory]` attribute, only a single directory path is supported.
|
|
1160
|
+
#
|
|
1161
|
+
# **Usage**
|
|
1162
|
+
#
|
|
1163
|
+
# ```python sync
|
|
1164
|
+
# # Select one file
|
|
1165
|
+
# page.get_by_label("Upload file").set_input_files('myfile.pdf')
|
|
1166
|
+
#
|
|
1167
|
+
# # Select multiple files
|
|
1168
|
+
# page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
|
|
1169
|
+
#
|
|
1170
|
+
# # Select a directory
|
|
1171
|
+
# page.get_by_label("Upload directory").set_input_files('mydir')
|
|
1172
|
+
#
|
|
1173
|
+
# # Remove all the selected files
|
|
1174
|
+
# page.get_by_label("Upload file").set_input_files([])
|
|
1175
|
+
#
|
|
1176
|
+
# # Upload buffer from memory
|
|
1177
|
+
# page.get_by_label("Upload file").set_input_files(
|
|
1178
|
+
# files=[
|
|
1179
|
+
# {"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
|
|
1180
|
+
# ],
|
|
1181
|
+
# )
|
|
1182
|
+
# ```
|
|
1183
|
+
#
|
|
1184
|
+
# **Details**
|
|
1185
|
+
#
|
|
1186
|
+
# Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
|
|
1187
|
+
# are resolved relative to the current working directory. For empty array, clears the selected files.
|
|
1188
|
+
#
|
|
1189
|
+
# This method expects `Locator` to point to an
|
|
1190
|
+
# [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.
|
|
1191
|
+
def set_input_files(files, noWaitAfter: nil, timeout: nil)
|
|
1192
|
+
wrap_impl(@impl.set_input_files(unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
1193
|
+
end
|
|
1194
|
+
alias_method :input_files=, :set_input_files
|
|
1195
|
+
|
|
1196
|
+
#
|
|
1197
|
+
# Perform a tap gesture on the element matching the locator. For examples of emulating other gestures by manually dispatching touch events, see the [emulating legacy touch events](../touch-events.md) page.
|
|
1198
|
+
#
|
|
1199
|
+
# **Details**
|
|
1200
|
+
#
|
|
1201
|
+
# This method taps the element by performing the following steps:
|
|
1202
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
1203
|
+
# 1. Scroll the element into view if needed.
|
|
1204
|
+
# 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
|
|
1205
|
+
#
|
|
1206
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
1207
|
+
#
|
|
1208
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
1209
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
1210
|
+
#
|
|
1211
|
+
# **NOTE**: `element.tap()` requires that the `hasTouch` option of the browser context be set to true.
|
|
1212
|
+
def tap_point(
|
|
1213
|
+
force: nil,
|
|
1214
|
+
modifiers: nil,
|
|
1215
|
+
noWaitAfter: nil,
|
|
1216
|
+
position: nil,
|
|
1217
|
+
timeout: nil,
|
|
1218
|
+
trial: nil)
|
|
1219
|
+
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)))
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
#
|
|
1223
|
+
# Returns the [`node.textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent).
|
|
1224
|
+
#
|
|
1225
|
+
# **NOTE**: If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
|
|
1226
|
+
def text_content(timeout: nil)
|
|
1227
|
+
wrap_impl(@impl.text_content(timeout: unwrap_impl(timeout)))
|
|
1228
|
+
end
|
|
1229
|
+
|
|
1230
|
+
#
|
|
1231
|
+
# Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
|
1232
|
+
#
|
|
1233
|
+
# To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
|
|
1234
|
+
#
|
|
1235
|
+
# **Usage**
|
|
1236
|
+
#
|
|
1237
|
+
# @deprecated In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [`method: Locator.pressSequentially`].
|
|
1238
|
+
def type(text, delay: nil, noWaitAfter: nil, timeout: nil)
|
|
1239
|
+
wrap_impl(@impl.type(unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
|
1240
|
+
end
|
|
1241
|
+
|
|
1242
|
+
#
|
|
1243
|
+
# Ensure that checkbox or radio element is unchecked.
|
|
1244
|
+
#
|
|
1245
|
+
# **Usage**
|
|
1246
|
+
#
|
|
1247
|
+
# ```python sync
|
|
1248
|
+
# page.get_by_role("checkbox").uncheck()
|
|
1249
|
+
# ```
|
|
1250
|
+
#
|
|
1251
|
+
# **Details**
|
|
1252
|
+
#
|
|
1253
|
+
# This method unchecks the element by performing the following steps:
|
|
1254
|
+
# 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already unchecked, this method returns immediately.
|
|
1255
|
+
# 1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
|
|
1256
|
+
# 1. Scroll the element into view if needed.
|
|
1257
|
+
# 1. Use [`property: Page.mouse`] to click in the center of the element.
|
|
1258
|
+
# 1. Ensure that the element is now unchecked. If not, this method throws.
|
|
1259
|
+
#
|
|
1260
|
+
# If the element is detached from the DOM at any moment during the action, this method throws.
|
|
1261
|
+
#
|
|
1262
|
+
# When all steps combined have not finished during the specified `timeout`, this method throws a
|
|
1263
|
+
# `TimeoutError`. Passing zero timeout disables this.
|
|
1264
|
+
def uncheck(
|
|
1265
|
+
force: nil,
|
|
1266
|
+
noWaitAfter: nil,
|
|
1267
|
+
position: nil,
|
|
1268
|
+
timeout: nil,
|
|
1269
|
+
trial: nil)
|
|
1270
|
+
wrap_impl(@impl.uncheck(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
|
1271
|
+
end
|
|
1272
|
+
|
|
1273
|
+
#
|
|
1274
|
+
# Returns when element specified by locator satisfies the `state` option.
|
|
1275
|
+
#
|
|
1276
|
+
# If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to
|
|
1277
|
+
# `timeout` milliseconds until the condition is met.
|
|
1278
|
+
#
|
|
1279
|
+
# **Usage**
|
|
1280
|
+
#
|
|
1281
|
+
# ```python sync
|
|
1282
|
+
# order_sent = page.locator("#order-sent")
|
|
1283
|
+
# order_sent.wait_for()
|
|
1284
|
+
# ```
|
|
1285
|
+
def wait_for(state: nil, timeout: nil)
|
|
1286
|
+
wrap_impl(@impl.wait_for(state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
|
|
1287
|
+
end
|
|
1288
|
+
|
|
1289
|
+
# @nodoc
|
|
1290
|
+
def resolve_selector
|
|
1291
|
+
wrap_impl(@impl.resolve_selector)
|
|
1292
|
+
end
|
|
1293
|
+
|
|
1294
|
+
# @nodoc
|
|
1295
|
+
def expect(expression, options, title)
|
|
1296
|
+
wrap_impl(@impl.expect(unwrap_impl(expression), unwrap_impl(options), unwrap_impl(title)))
|
|
1297
|
+
end
|
|
1298
|
+
|
|
1299
|
+
# @nodoc
|
|
1300
|
+
def to_s
|
|
1301
|
+
wrap_impl(@impl.to_s)
|
|
1302
|
+
end
|
|
1303
|
+
end
|
|
1304
|
+
end
|