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