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,1946 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # Page
6
+
7
+
8
+ Page provides methods to interact with a single tab in a [Browser](./browser), or an
9
+ [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser](./browser)
10
+ instance might have multiple [Page](./page) instances.
11
+
12
+ This example creates a page, navigates it to a URL, and then saves a screenshot:
13
+
14
+ ```ruby
15
+ playwright.webkit.launch do |browser|
16
+ page = browser.new_page
17
+ page.goto('https://example.com/')
18
+ page.screenshot(path: 'screenshot.png')
19
+ end
20
+ ```
21
+
22
+ The Page class emits various events (described below) which can be handled using any of Node's native
23
+ [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or
24
+ `removeListener`.
25
+
26
+ This example logs a message for a single page `load` event:
27
+
28
+ ```ruby
29
+ page.once("load", -> (page) { puts "page loaded!" })
30
+ ```
31
+
32
+ To unsubscribe from events use the `removeListener` method:
33
+
34
+ ```ruby
35
+ listener = -> (req) { puts "a request was made: #{req.url}" }
36
+ page.on('request', listener)
37
+ page.goto('https://example.com/') # => prints 'a request was made: https://example.com/'
38
+ page.off('request', listener)
39
+ page.goto('https://example.com/') # => no print
40
+ ```
41
+
42
+ ## add_init_script
43
+
44
+ ```
45
+ def add_init_script(path: nil, script: nil)
46
+ ```
47
+
48
+
49
+ Adds a script which would be evaluated in one of the following scenarios:
50
+ - Whenever the page is navigated.
51
+ - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
52
+
53
+ The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
54
+ the JavaScript environment, e.g. to seed `Math.random`.
55
+
56
+ **Usage**
57
+
58
+ An example of overriding `Math.random` before the page loads:
59
+
60
+ ```ruby
61
+ # in your playwright script, assuming the preload.js file is in same directory
62
+ page.add_init_script(path: "./preload.js")
63
+ ```
64
+
65
+ **NOTE**: The order of evaluation of multiple scripts installed via [BrowserContext#add_init_script](./browser_context#add_init_script) and
66
+ [Page#add_init_script](./page#add_init_script) is not defined.
67
+
68
+ ## add_script_tag
69
+
70
+ ```
71
+ def add_script_tag(content: nil, path: nil, type: nil, url: nil)
72
+ ```
73
+
74
+
75
+ Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
76
+ fires or when the script content was injected into frame.
77
+
78
+ ## add_style_tag
79
+
80
+ ```
81
+ def add_style_tag(content: nil, path: nil, url: nil)
82
+ ```
83
+
84
+
85
+ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
86
+ content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
87
+
88
+ ## bring_to_front
89
+
90
+ ```
91
+ def bring_to_front
92
+ ```
93
+
94
+
95
+ Brings page to front (activates tab).
96
+
97
+ ## check
98
+
99
+ ```
100
+ def check(
101
+ selector,
102
+ force: nil,
103
+ noWaitAfter: nil,
104
+ position: nil,
105
+ strict: nil,
106
+ timeout: nil,
107
+ trial: nil)
108
+ ```
109
+
110
+
111
+ This method checks an element matching `selector` by performing the following steps:
112
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
113
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
114
+ 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.
115
+ 1. Scroll the element into view if needed.
116
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
117
+ 1. Ensure that the element is now checked. If not, this method throws.
118
+
119
+ When all steps combined have not finished during the specified `timeout`, this method throws a
120
+ `TimeoutError`. Passing zero timeout disables this.
121
+
122
+ ## click
123
+
124
+ ```
125
+ def click(
126
+ selector,
127
+ button: nil,
128
+ clickCount: nil,
129
+ delay: nil,
130
+ force: nil,
131
+ modifiers: nil,
132
+ noWaitAfter: nil,
133
+ position: nil,
134
+ strict: nil,
135
+ timeout: nil,
136
+ trial: nil)
137
+ ```
138
+
139
+
140
+ This method clicks an element matching `selector` by performing the following steps:
141
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
142
+ 1. Wait for [actionability](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.
143
+ 1. Scroll the element into view if needed.
144
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element, or the specified `position`.
145
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
146
+
147
+ When all steps combined have not finished during the specified `timeout`, this method throws a
148
+ `TimeoutError`. Passing zero timeout disables this.
149
+
150
+ ## close
151
+
152
+ ```
153
+ def close(reason: nil, runBeforeUnload: nil)
154
+ ```
155
+
156
+
157
+ If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
158
+ `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
159
+
160
+ By default, `page.close()` **does not** run `beforeunload` handlers.
161
+
162
+ **NOTE**: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled
163
+ manually via [`event: Page.dialog`] event.
164
+
165
+ ## content
166
+
167
+ ```
168
+ def content
169
+ ```
170
+
171
+
172
+ Gets the full HTML contents of the page, including the doctype.
173
+
174
+ ## context
175
+
176
+ ```
177
+ def context
178
+ ```
179
+
180
+
181
+ Get the browser context that the page belongs to.
182
+
183
+ ## dblclick
184
+
185
+ ```
186
+ def dblclick(
187
+ selector,
188
+ button: nil,
189
+ delay: nil,
190
+ force: nil,
191
+ modifiers: nil,
192
+ noWaitAfter: nil,
193
+ position: nil,
194
+ strict: nil,
195
+ timeout: nil,
196
+ trial: nil)
197
+ ```
198
+
199
+
200
+ This method double clicks an element matching `selector` by performing the following steps:
201
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
202
+ 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.
203
+ 1. Scroll the element into view if needed.
204
+ 1. Use [Page#mouse](./page#mouse) to double click in the center of the element, or the specified `position`.
205
+
206
+ When all steps combined have not finished during the specified `timeout`, this method throws a
207
+ `TimeoutError`. Passing zero timeout disables this.
208
+
209
+ **NOTE**: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
210
+
211
+ ## dispatch_event
212
+
213
+ ```
214
+ def dispatch_event(
215
+ selector,
216
+ type,
217
+ eventInit: nil,
218
+ strict: nil,
219
+ timeout: nil)
220
+ ```
221
+
222
+
223
+ The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, `click`
224
+ is dispatched. This is equivalent to calling
225
+ [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
226
+
227
+ **Usage**
228
+
229
+ ```ruby
230
+ page.content = '<button id="submit">Send</button>'
231
+ page.dispatch_event("button#submit", "click")
232
+ ```
233
+
234
+ Under the hood, it creates an instance of an event based on the given `type`, initializes it with
235
+ `eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
236
+ default.
237
+
238
+ Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
239
+ properties:
240
+ - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
241
+ - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
242
+ - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
243
+ - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
244
+ - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
245
+ - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
246
+ - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
247
+ - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
248
+ - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
249
+ - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
250
+
251
+ You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
252
+
253
+ ```ruby
254
+ page.content = '<div id="source">Drag</div>'
255
+
256
+ data_transfer = page.evaluate_handle("new DataTransfer()")
257
+ page.dispatch_event("#source", "dragstart", eventInit: { dataTransfer: data_transfer })
258
+ ```
259
+
260
+ ## drag_and_drop
261
+
262
+ ```
263
+ def drag_and_drop(
264
+ source,
265
+ target,
266
+ force: nil,
267
+ noWaitAfter: nil,
268
+ sourcePosition: nil,
269
+ steps: nil,
270
+ strict: nil,
271
+ targetPosition: nil,
272
+ timeout: nil,
273
+ trial: nil)
274
+ ```
275
+
276
+
277
+ This method drags the source element to the target element.
278
+ It will first move to the source element, perform a `mousedown`,
279
+ then move to the target element and perform a `mouseup`.
280
+
281
+ **Usage**
282
+
283
+ ```ruby
284
+ page.drag_and_drop("#source", "#target")
285
+ # or specify exact positions relative to the top-left corners of the elements:
286
+ page.drag_and_drop(
287
+ "#source",
288
+ "#target",
289
+ sourcePosition: { x: 34, y: 7 },
290
+ targetPosition: { x: 10, y: 20 },
291
+ )
292
+ ```
293
+
294
+ ## emulate_media
295
+
296
+ ```
297
+ def emulate_media(
298
+ colorScheme: nil,
299
+ contrast: nil,
300
+ forcedColors: nil,
301
+ media: nil,
302
+ reducedMotion: nil)
303
+ ```
304
+
305
+
306
+ This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media feature, using the `colorScheme` argument.
307
+
308
+ **Usage**
309
+
310
+ ```ruby
311
+ page.evaluate("matchMedia('screen').matches") # => true
312
+ page.evaluate("matchMedia('print').matches") # => false
313
+
314
+ page.emulate_media(media: "print")
315
+ page.evaluate("matchMedia('screen').matches") # => false
316
+ page.evaluate("matchMedia('print').matches") # => true
317
+
318
+ page.emulate_media
319
+ page.evaluate("matchMedia('screen').matches") # => true
320
+ page.evaluate("matchMedia('print').matches") # => false
321
+ ```
322
+
323
+ ```ruby
324
+ page.emulate_media(colorScheme: "dark")
325
+ page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches") # => true
326
+ page.evaluate("matchMedia('(prefers-color-scheme: light)').matches") # => false
327
+ ```
328
+
329
+ ## eval_on_selector
330
+
331
+ ```
332
+ def eval_on_selector(selector, expression, arg: nil, strict: nil)
333
+ ```
334
+
335
+
336
+ The method finds an element matching the specified selector within the page and passes it as a first argument to
337
+ `expression`. If no elements match the selector, the method throws an error. Returns the value of
338
+ `expression`.
339
+
340
+ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Page#eval_on_selector](./page#eval_on_selector) would wait for the promise to resolve and
341
+ return its value.
342
+
343
+ **Usage**
344
+
345
+ ```ruby
346
+ search_value = page.eval_on_selector("#search", "el => el.value")
347
+ preload_href = page.eval_on_selector("link[rel=preload]", "el => el.href")
348
+ html = page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", arg: "hello")
349
+ ```
350
+
351
+ ## eval_on_selector_all
352
+
353
+ ```
354
+ def eval_on_selector_all(selector, expression, arg: nil)
355
+ ```
356
+
357
+
358
+ The method finds all elements matching the specified selector within the page and passes an array of matched elements as
359
+ a first argument to `expression`. Returns the result of `expression` invocation.
360
+
361
+ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Page#eval_on_selector_all](./page#eval_on_selector_all) would wait for the promise to resolve and
362
+ return its value.
363
+
364
+ **Usage**
365
+
366
+ ```ruby
367
+ div_counts = page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", arg: 10)
368
+ ```
369
+
370
+ ## evaluate
371
+
372
+ ```
373
+ def evaluate(expression, arg: nil)
374
+ ```
375
+
376
+
377
+ Returns the value of the `expression` invocation.
378
+
379
+ If the function passed to the [Page#evaluate](./page#evaluate) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Page#evaluate](./page#evaluate) would wait
380
+ for the promise to resolve and return its value.
381
+
382
+ If the function passed to the [Page#evaluate](./page#evaluate) returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) value, then
383
+ [Page#evaluate](./page#evaluate) resolves to `undefined`. Playwright also supports transferring some
384
+ additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
385
+
386
+ **Usage**
387
+
388
+ Passing argument to `expression`:
389
+
390
+ ```ruby
391
+ result = page.evaluate("([x, y]) => Promise.resolve(x * y)", arg: [7, 8])
392
+ puts result # => "56"
393
+ ```
394
+
395
+ A string can also be passed in instead of a function:
396
+
397
+ ```ruby
398
+ puts page.evaluate("1 + 2") # => 3
399
+ x = 10
400
+ puts page.evaluate("1 + #{x}") # => "11"
401
+ ```
402
+
403
+ [ElementHandle](./element_handle) instances can be passed as an argument to the [Page#evaluate](./page#evaluate):
404
+
405
+ ```ruby
406
+ body_handle = page.query_selector("body")
407
+ html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", arg: [body_handle, "hello"])
408
+ body_handle.dispose
409
+ ```
410
+
411
+ ## evaluate_handle
412
+
413
+ ```
414
+ def evaluate_handle(expression, arg: nil)
415
+ ```
416
+
417
+
418
+ Returns the value of the `expression` invocation as a [JSHandle](./js_handle).
419
+
420
+ The only difference between [Page#evaluate](./page#evaluate) and [Page#evaluate_handle](./page#evaluate_handle) is that [Page#evaluate_handle](./page#evaluate_handle) returns [JSHandle](./js_handle).
421
+
422
+ If the function passed to the [Page#evaluate_handle](./page#evaluate_handle) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Page#evaluate_handle](./page#evaluate_handle) would wait for the
423
+ promise to resolve and return its value.
424
+
425
+ **Usage**
426
+
427
+ ```ruby
428
+ a_window_handle = page.evaluate_handle("Promise.resolve(window)")
429
+ a_window_handle # handle for the window object.
430
+ ```
431
+
432
+ A string can also be passed in instead of a function:
433
+
434
+ ```ruby
435
+ a_handle = page.evaluate_handle("document") # handle for the "document"
436
+ ```
437
+
438
+ [JSHandle](./js_handle) instances can be passed as an argument to the [Page#evaluate_handle](./page#evaluate_handle):
439
+
440
+ ```ruby
441
+ body_handle = page.evaluate_handle("document.body")
442
+ result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
443
+ puts result_handle.json_value
444
+ result_handle.dispose
445
+ ```
446
+
447
+ ## expose_binding
448
+
449
+ ```
450
+ def expose_binding(name, callback, handle: nil)
451
+ ```
452
+
453
+
454
+ The method adds a function called `name` on the `window` object of every frame in this page. When called, the
455
+ function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of `callback`.
456
+ If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
457
+
458
+ The first argument of the `callback` function contains information about the caller: `{ browserContext:
459
+ BrowserContext, page: Page, frame: Frame }`.
460
+
461
+ See [BrowserContext#expose_binding](./browser_context#expose_binding) for the context-wide version.
462
+
463
+ **NOTE**: Functions installed via [Page#expose_binding](./page#expose_binding) survive navigations.
464
+
465
+ **Usage**
466
+
467
+ An example of exposing page URL to all frames in a page:
468
+
469
+ ```ruby
470
+ page.expose_binding("pageURL", ->(source) { source[:page].url })
471
+ page.content = <<~HTML
472
+ <script>
473
+ async function onClick() {
474
+ document.querySelector('div').textContent = await window.pageURL();
475
+ }
476
+ </script>
477
+ <button onclick="onClick()">Click me</button>
478
+ <div></div>
479
+ HTML
480
+ page.click("button")
481
+ ```
482
+
483
+ ## expose_function
484
+
485
+ ```
486
+ def expose_function(name, callback)
487
+ ```
488
+
489
+
490
+ The method adds a function called `name` on the `window` object of every frame in the page. When called, the
491
+ function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of `callback`.
492
+
493
+ If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
494
+
495
+ See [BrowserContext#expose_function](./browser_context#expose_function) for context-wide exposed function.
496
+
497
+ **NOTE**: Functions installed via [Page#expose_function](./page#expose_function) survive navigations.
498
+
499
+ **Usage**
500
+
501
+ An example of adding a `sha256` function to the page:
502
+
503
+ ```ruby
504
+ require 'digest'
505
+
506
+ def sha256(text)
507
+ Digest::SHA256.hexdigest(text)
508
+ end
509
+
510
+ page.expose_function("sha256", method(:sha256))
511
+ page.content = <<~HTML
512
+ <script>
513
+ async function onClick() {
514
+ document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
515
+ }
516
+ </script>
517
+ <button onclick="onClick()">Click me</button>
518
+ <div></div>
519
+ HTML
520
+ page.locator("button").click
521
+ ```
522
+
523
+ ## fill
524
+
525
+ ```
526
+ def fill(
527
+ selector,
528
+ value,
529
+ force: nil,
530
+ noWaitAfter: nil,
531
+ strict: nil,
532
+ timeout: nil)
533
+ ```
534
+
535
+
536
+ This method waits for an element matching `selector`, 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.
537
+
538
+ 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.
539
+
540
+ To send fine-grained keyboard events, use [Locator#press_sequentially](./locator#press_sequentially).
541
+
542
+ ## focus
543
+
544
+ ```
545
+ def focus(selector, strict: nil, timeout: nil)
546
+ ```
547
+
548
+
549
+ This method fetches an element with `selector` and focuses it. If there's no element matching
550
+ `selector`, the method waits until a matching element appears in the DOM.
551
+
552
+ ## frame
553
+
554
+ ```
555
+ def frame(name: nil, url: nil)
556
+ ```
557
+
558
+
559
+ Returns frame matching the specified criteria. Either `name` or `url` must be specified.
560
+
561
+ **Usage**
562
+
563
+ ```ruby
564
+ frame = page.frame(name: "frame-name")
565
+ ```
566
+
567
+ ```ruby
568
+ frame = page.frame(url: /.*domain.*/)
569
+ ```
570
+
571
+ ## frame_locator
572
+
573
+ ```
574
+ def frame_locator(selector)
575
+ ```
576
+
577
+
578
+ When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements
579
+ in that iframe.
580
+
581
+ **Usage**
582
+
583
+ Following snippet locates element with text "Submit" in the iframe with id `my-frame`,
584
+ like `<iframe id="my-frame">`:
585
+
586
+ ```ruby
587
+ locator = page.frame_locator("#my-iframe").get_by_text("Submit")
588
+ locator.click
589
+ ```
590
+
591
+ ## frames
592
+
593
+ ```
594
+ def frames
595
+ ```
596
+
597
+
598
+ An array of all frames attached to the page.
599
+
600
+ ## get_attribute
601
+
602
+ ```
603
+ def get_attribute(selector, name, strict: nil, timeout: nil)
604
+ ```
605
+
606
+
607
+ Returns element attribute value.
608
+
609
+ ## get_by_alt_text
610
+
611
+ ```
612
+ def get_by_alt_text(text, exact: nil)
613
+ ```
614
+
615
+
616
+ Allows locating elements by their alt text.
617
+
618
+ **Usage**
619
+
620
+ For example, this method will find the image by alt text "Playwright logo":
621
+
622
+ ```html
623
+ <img alt='Playwright logo'>
624
+ ```
625
+
626
+ ```ruby
627
+ page.get_by_alt_text("Playwright logo").click
628
+ ```
629
+
630
+ ## get_by_label
631
+
632
+ ```
633
+ def get_by_label(text, exact: nil)
634
+ ```
635
+
636
+
637
+ Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the `aria-label` attribute.
638
+
639
+ **Usage**
640
+
641
+ For example, this method will find inputs by label "Username" and "Password" in the following DOM:
642
+
643
+ ```html
644
+ <input aria-label="Username">
645
+ <label for="password-input">Password:</label>
646
+ <input id="password-input">
647
+ ```
648
+
649
+ ```ruby
650
+ page.get_by_label("Username").fill("john")
651
+ page.get_by_label("Password").fill("secret")
652
+ ```
653
+
654
+ ## get_by_placeholder
655
+
656
+ ```
657
+ def get_by_placeholder(text, exact: nil)
658
+ ```
659
+
660
+
661
+ Allows locating input elements by the placeholder text.
662
+
663
+ **Usage**
664
+
665
+ For example, consider the following DOM structure.
666
+
667
+ ```html
668
+ <input type="email" placeholder="name@example.com" />
669
+ ```
670
+
671
+ You can fill the input after locating it by the placeholder text:
672
+
673
+ ```ruby
674
+ page.get_by_placeholder("name@example.com").fill("playwright@microsoft.com")
675
+ ```
676
+
677
+ ## get_by_role
678
+
679
+ ```
680
+ def get_by_role(
681
+ role,
682
+ checked: nil,
683
+ disabled: nil,
684
+ exact: nil,
685
+ expanded: nil,
686
+ includeHidden: nil,
687
+ level: nil,
688
+ name: nil,
689
+ pressed: nil,
690
+ selected: nil)
691
+ ```
692
+
693
+
694
+ 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).
695
+
696
+ **Usage**
697
+
698
+ Consider the following DOM structure.
699
+
700
+ ```html
701
+ <h3>Sign up</h3>
702
+ <label>
703
+ <input type="checkbox" /> Subscribe
704
+ </label>
705
+ <br/>
706
+ <button>Submit</button>
707
+ ```
708
+
709
+ You can locate each element by it's implicit role:
710
+
711
+ ```ruby
712
+ page.get_by_role("heading", name: "Sign up").visible? # => true
713
+ page.get_by_role("checkbox", name: "Subscribe").check
714
+ page.get_by_role("button", name: /submit/i).click
715
+ ```
716
+
717
+ **Details**
718
+
719
+ Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
720
+
721
+ 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.
722
+
723
+ ## get_by_test_id
724
+
725
+ ```
726
+ def get_by_test_id(testId)
727
+ ```
728
+ alias: `get_by_testid`
729
+
730
+
731
+ Locate element by the test id.
732
+
733
+ **Usage**
734
+
735
+ Consider the following DOM structure.
736
+
737
+ ```html
738
+ <button data-testid="directions">Itinéraire</button>
739
+ ```
740
+
741
+ You can locate the element by it's test id:
742
+
743
+ ```ruby
744
+ page.get_by_test_id("directions").click
745
+ ```
746
+
747
+ **Details**
748
+
749
+ 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.
750
+
751
+ ## get_by_text
752
+
753
+ ```
754
+ def get_by_text(text, exact: nil)
755
+ ```
756
+
757
+
758
+ Allows locating elements that contain given text.
759
+
760
+ See also [Locator#filter](./locator#filter) that allows to match by another criteria, like an accessible role, and then filter by the text content.
761
+
762
+ **Usage**
763
+
764
+ Consider the following DOM structure:
765
+
766
+ ```html
767
+ <div>Hello <span>world</span></div>
768
+ <div>Hello</div>
769
+ ```
770
+
771
+ You can locate by text substring, exact string, or a regular expression:
772
+
773
+ ```ruby
774
+ page.content = <<~HTML
775
+ <div>Hello <span>world</span></div>
776
+ <div>Hello</div>
777
+ HTML
778
+
779
+ # Matches <span>
780
+ locator = page.get_by_text("world")
781
+ expect(locator.evaluate('e => e.outerHTML')).to eq('<span>world</span>')
782
+
783
+ # Matches first <div>
784
+ locator = page.get_by_text("Hello world")
785
+ expect(locator.evaluate('e => e.outerHTML')).to eq('<div>Hello <span>world</span></div>')
786
+
787
+ # Matches second <div>
788
+ locator = page.get_by_text("Hello", exact: true)
789
+ expect(locator.evaluate('e => e.outerHTML')).to eq('<div>Hello</div>')
790
+
791
+ # Matches both <div>s
792
+ locator = page.get_by_text(/Hello/)
793
+ expect(locator.count).to eq(2)
794
+ expect(locator.first.evaluate('e => e.outerHTML')).to eq('<div>Hello <span>world</span></div>')
795
+ expect(locator.last.evaluate('e => e.outerHTML')).to eq('<div>Hello</div>')
796
+
797
+ # Matches second <div>
798
+ locator = page.get_by_text(/^hello$/i)
799
+ expect(locator.evaluate('e => e.outerHTML')).to eq('<div>Hello</div>')
800
+ ```
801
+
802
+ **Details**
803
+
804
+ 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.
805
+
806
+ 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">`.
807
+
808
+ ## get_by_title
809
+
810
+ ```
811
+ def get_by_title(text, exact: nil)
812
+ ```
813
+
814
+
815
+ Allows locating elements by their title attribute.
816
+
817
+ **Usage**
818
+
819
+ Consider the following DOM structure.
820
+
821
+ ```html
822
+ <span title='Issues count'>25 issues</span>
823
+ ```
824
+
825
+ You can check the issues count after locating it by the title text:
826
+
827
+ ```ruby
828
+ page.get_by_title("Issues count").text_content # => "25 issues"
829
+ ```
830
+
831
+ ## go_back
832
+
833
+ ```
834
+ def go_back(timeout: nil, waitUntil: nil)
835
+ ```
836
+
837
+
838
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
839
+ last redirect. If cannot go back, returns `null`.
840
+
841
+ Navigate to the previous page in history.
842
+
843
+ ## go_forward
844
+
845
+ ```
846
+ def go_forward(timeout: nil, waitUntil: nil)
847
+ ```
848
+
849
+
850
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
851
+ last redirect. If cannot go forward, returns `null`.
852
+
853
+ Navigate to the next page in history.
854
+
855
+ ## goto
856
+
857
+ ```
858
+ def goto(url, referer: nil, timeout: nil, waitUntil: nil)
859
+ ```
860
+
861
+
862
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first
863
+ non-redirect response.
864
+
865
+ The method will throw an error if:
866
+ - there's an SSL error (e.g. in case of self-signed certificates).
867
+ - target URL is invalid.
868
+ - the `timeout` is exceeded during navigation.
869
+ - the remote server does not respond or is unreachable.
870
+ - the main resource failed to load.
871
+
872
+ The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
873
+ Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
874
+ [Response#status](./response#status).
875
+
876
+ **NOTE**: The method either throws an error or returns a main resource response. The only exceptions are navigation to
877
+ `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
878
+
879
+ **NOTE**: Headless mode doesn't support navigation to a PDF document. See the
880
+ [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
881
+
882
+ ## hover
883
+
884
+ ```
885
+ def hover(
886
+ selector,
887
+ force: nil,
888
+ modifiers: nil,
889
+ noWaitAfter: nil,
890
+ position: nil,
891
+ strict: nil,
892
+ timeout: nil,
893
+ trial: nil)
894
+ ```
895
+
896
+
897
+ This method hovers over an element matching `selector` by performing the following steps:
898
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
899
+ 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.
900
+ 1. Scroll the element into view if needed.
901
+ 1. Use [Page#mouse](./page#mouse) to hover over the center of the element, or the specified `position`.
902
+
903
+ When all steps combined have not finished during the specified `timeout`, this method throws a
904
+ `TimeoutError`. Passing zero timeout disables this.
905
+
906
+ ## inner_html
907
+
908
+ ```
909
+ def inner_html(selector, strict: nil, timeout: nil)
910
+ ```
911
+
912
+
913
+ Returns `element.innerHTML`.
914
+
915
+ ## inner_text
916
+
917
+ ```
918
+ def inner_text(selector, strict: nil, timeout: nil)
919
+ ```
920
+
921
+
922
+ Returns `element.innerText`.
923
+
924
+ ## input_value
925
+
926
+ ```
927
+ def input_value(selector, strict: nil, timeout: nil)
928
+ ```
929
+
930
+
931
+ Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.
932
+
933
+ Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.
934
+
935
+ ## checked?
936
+
937
+ ```
938
+ def checked?(selector, strict: nil, timeout: nil)
939
+ ```
940
+
941
+
942
+ Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
943
+
944
+ ## closed?
945
+
946
+ ```
947
+ def closed?
948
+ ```
949
+
950
+
951
+ Indicates that the page has been closed.
952
+
953
+ ## disabled?
954
+
955
+ ```
956
+ def disabled?(selector, strict: nil, timeout: nil)
957
+ ```
958
+
959
+
960
+ Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability#enabled).
961
+
962
+ ## editable?
963
+
964
+ ```
965
+ def editable?(selector, strict: nil, timeout: nil)
966
+ ```
967
+
968
+
969
+ Returns whether the element is [editable](https://playwright.dev/python/docs/actionability#editable).
970
+
971
+ ## enabled?
972
+
973
+ ```
974
+ def enabled?(selector, strict: nil, timeout: nil)
975
+ ```
976
+
977
+
978
+ Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability#enabled).
979
+
980
+ ## hidden?
981
+
982
+ ```
983
+ def hidden?(selector, strict: nil, timeout: nil)
984
+ ```
985
+
986
+
987
+ Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability#visible). `selector` that does not match any elements is considered hidden.
988
+
989
+ ## visible?
990
+
991
+ ```
992
+ def visible?(selector, strict: nil, timeout: nil)
993
+ ```
994
+
995
+
996
+ Returns whether the element is [visible](https://playwright.dev/python/docs/actionability#visible). `selector` that does not match any elements is considered not visible.
997
+
998
+ ## console_messages
999
+
1000
+ ```
1001
+ def console_messages
1002
+ ```
1003
+
1004
+
1005
+ Returns up to (currently) 200 last console messages from this page. See [`event: Page.console`] for more details.
1006
+
1007
+ ## page_errors
1008
+
1009
+ ```
1010
+ def page_errors
1011
+ ```
1012
+
1013
+
1014
+ Returns up to (currently) 200 last page errors from this page. See [`event: Page.pageError`] for more details.
1015
+
1016
+ ## locator
1017
+
1018
+ ```
1019
+ def locator(
1020
+ selector,
1021
+ has: nil,
1022
+ hasNot: nil,
1023
+ hasNotText: nil,
1024
+ hasText: nil)
1025
+ ```
1026
+
1027
+
1028
+ The method returns an element locator that can be used to perform actions on this page / frame.
1029
+ Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
1030
+
1031
+ [Learn more about locators](https://playwright.dev/python/docs/locators).
1032
+
1033
+ ## main_frame
1034
+
1035
+ ```
1036
+ def main_frame
1037
+ ```
1038
+
1039
+
1040
+ The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
1041
+
1042
+ ## opener
1043
+
1044
+ ```
1045
+ def opener
1046
+ ```
1047
+
1048
+
1049
+ Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
1050
+
1051
+ ## pause
1052
+
1053
+ ```
1054
+ def pause
1055
+ ```
1056
+
1057
+
1058
+ Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume'
1059
+ button in the page overlay or to call `playwright.resume()` in the DevTools console.
1060
+
1061
+ User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
1062
+ the place it was paused.
1063
+
1064
+ **NOTE**: This method requires Playwright to be started in a headed mode, with a falsy `headless` option.
1065
+
1066
+ ## pdf
1067
+
1068
+ ```
1069
+ def pdf(
1070
+ displayHeaderFooter: nil,
1071
+ footerTemplate: nil,
1072
+ format: nil,
1073
+ headerTemplate: nil,
1074
+ height: nil,
1075
+ landscape: nil,
1076
+ margin: nil,
1077
+ outline: nil,
1078
+ pageRanges: nil,
1079
+ path: nil,
1080
+ preferCSSPageSize: nil,
1081
+ printBackground: nil,
1082
+ scale: nil,
1083
+ tagged: nil,
1084
+ width: nil)
1085
+ ```
1086
+
1087
+
1088
+ Returns the PDF buffer.
1089
+
1090
+ `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
1091
+ [Page#emulate_media](./page#emulate_media) before calling `page.pdf()`:
1092
+
1093
+ **NOTE**: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
1094
+ [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
1095
+ force rendering of exact colors.
1096
+
1097
+ **Usage**
1098
+
1099
+ ```ruby
1100
+ # generates a pdf with "screen" media type.
1101
+ page.emulate_media(media: "screen")
1102
+ page.pdf(path: "page.pdf")
1103
+ ```
1104
+
1105
+ The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled
1106
+ values are treated as pixels.
1107
+
1108
+ A few examples:
1109
+ - `page.pdf({width: 100})` - prints with width set to 100 pixels
1110
+ - `page.pdf({width: '100px'})` - prints with width set to 100 pixels
1111
+ - `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
1112
+
1113
+ All possible units are:
1114
+ - `px` - pixel
1115
+ - `in` - inch
1116
+ - `cm` - centimeter
1117
+ - `mm` - millimeter
1118
+
1119
+ The `format` options are:
1120
+ - `Letter`: 8.5in x 11in
1121
+ - `Legal`: 8.5in x 14in
1122
+ - `Tabloid`: 11in x 17in
1123
+ - `Ledger`: 17in x 11in
1124
+ - `A0`: 33.1in x 46.8in
1125
+ - `A1`: 23.4in x 33.1in
1126
+ - `A2`: 16.54in x 23.4in
1127
+ - `A3`: 11.7in x 16.54in
1128
+ - `A4`: 8.27in x 11.7in
1129
+ - `A5`: 5.83in x 8.27in
1130
+ - `A6`: 4.13in x 5.83in
1131
+
1132
+ **NOTE**: `headerTemplate` and `footerTemplate` markup have the following limitations: > 1. Script tags inside
1133
+ templates are not evaluated. > 2. Page styles are not visible inside templates.
1134
+
1135
+ ## press
1136
+
1137
+ ```
1138
+ def press(
1139
+ selector,
1140
+ key,
1141
+ delay: nil,
1142
+ noWaitAfter: nil,
1143
+ strict: nil,
1144
+ timeout: nil)
1145
+ ```
1146
+
1147
+
1148
+ Focuses the element, and then uses [Keyboard#down](./keyboard#down) and [Keyboard#up](./keyboard#up).
1149
+
1150
+ `key` can specify the intended
1151
+ [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
1152
+ generate the text for. A superset of the `key` values can be found
1153
+ [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
1154
+
1155
+ `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
1156
+ `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
1157
+
1158
+ Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, `ControlOrMeta`.
1159
+ `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS.
1160
+
1161
+ Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
1162
+
1163
+ If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
1164
+ respective texts.
1165
+
1166
+ Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When specified with the
1167
+ modifier, modifier is pressed and being held while the subsequent key is being pressed.
1168
+
1169
+ **Usage**
1170
+
1171
+ ```ruby
1172
+ page.goto("https://keycode.info")
1173
+ page.press("body", "A")
1174
+ page.screenshot(path: "a.png")
1175
+ page.press("body", "ArrowLeft")
1176
+ page.screenshot(path: "arrow_left.png")
1177
+ page.press("body", "Shift+O")
1178
+ page.screenshot(path: "o.png")
1179
+ ```
1180
+
1181
+ ## query_selector
1182
+
1183
+ ```
1184
+ def query_selector(selector, strict: nil)
1185
+ ```
1186
+
1187
+
1188
+ The method finds an element matching the specified selector within the page. If no elements match the selector, the
1189
+ return value resolves to `null`. To wait for an element on the page, use [Locator#wait_for](./locator#wait_for).
1190
+
1191
+ ## query_selector_all
1192
+
1193
+ ```
1194
+ def query_selector_all(selector)
1195
+ ```
1196
+
1197
+
1198
+ The method finds all elements matching the specified selector within the page. If no elements match the selector, the
1199
+ return value resolves to `[]`.
1200
+
1201
+ ## requests
1202
+
1203
+ ```
1204
+ def requests
1205
+ ```
1206
+
1207
+
1208
+ Returns up to (currently) 100 last network request from this page. See [`event: Page.request`] for more details.
1209
+
1210
+ Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory growth as new requests come in. Once collected, retrieving most information about the request is impossible.
1211
+
1212
+ Note that requests reported through the [`event: Page.request`] request are not collected, so there is a trade off between efficient memory usage with [Page#requests](./page#requests) and the amount of available information reported through [`event: Page.request`].
1213
+
1214
+ ## reload
1215
+
1216
+ ```
1217
+ def reload(timeout: nil, waitUntil: nil)
1218
+ ```
1219
+
1220
+
1221
+ This method reloads the current page, in the same way as if the user had triggered a browser refresh.
1222
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1223
+ last redirect.
1224
+
1225
+ ## route
1226
+
1227
+ ```
1228
+ def route(url, handler, times: nil)
1229
+ ```
1230
+
1231
+
1232
+ Routing provides the capability to modify network requests that are made by a page.
1233
+
1234
+ Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
1235
+
1236
+ **NOTE**: The handler will only be called for the first url if the response is a redirect.
1237
+
1238
+ **NOTE**: [Page#route](./page#route) will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `serviceWorkers` to `'block'`.
1239
+
1240
+ **NOTE**: [Page#route](./page#route) will not intercept the first request of a popup page. Use [BrowserContext#route](./browser_context#route) instead.
1241
+
1242
+ **Usage**
1243
+
1244
+ An example of a naive handler that aborts all image requests:
1245
+
1246
+ ```ruby
1247
+ page.route("**/*.{png,jpg,jpeg}", ->(route, request) { route.abort })
1248
+ page.goto("https://example.com")
1249
+ ```
1250
+
1251
+ or the same snippet using a regex pattern instead:
1252
+
1253
+ ```ruby
1254
+ page.route(/\.(png|jpg)$/, ->(route, request) { route.abort })
1255
+ page.goto("https://example.com")
1256
+ ```
1257
+
1258
+ It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
1259
+
1260
+ ```ruby
1261
+ def handle_route(route, request)
1262
+ if request.post_data["my-string"]
1263
+ mocked_data = request.post_data.merge({ "my-string" => 'mocked-data'})
1264
+ route.fulfill(postData: mocked_data)
1265
+ else
1266
+ route.continue
1267
+ end
1268
+ end
1269
+ page.route("/api/**", method(:handle_route))
1270
+ ```
1271
+
1272
+ Page routes take precedence over browser context routes (set up with [BrowserContext#route](./browser_context#route)) when request
1273
+ matches both handlers.
1274
+
1275
+ To remove a route with its handler you can use [Page#unroute](./page#unroute).
1276
+
1277
+ **NOTE**: Enabling routing disables http cache.
1278
+
1279
+ ## route_from_har
1280
+
1281
+ ```
1282
+ def route_from_har(
1283
+ har,
1284
+ notFound: nil,
1285
+ update: nil,
1286
+ updateContent: nil,
1287
+ updateMode: nil,
1288
+ url: nil)
1289
+ ```
1290
+
1291
+
1292
+ If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](https://playwright.dev/python/docs/mock#replaying-from-har).
1293
+
1294
+ Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `serviceWorkers` to `'block'`.
1295
+
1296
+ ## screenshot
1297
+
1298
+ ```
1299
+ def screenshot(
1300
+ animations: nil,
1301
+ caret: nil,
1302
+ clip: nil,
1303
+ fullPage: nil,
1304
+ mask: nil,
1305
+ maskColor: nil,
1306
+ omitBackground: nil,
1307
+ path: nil,
1308
+ quality: nil,
1309
+ scale: nil,
1310
+ style: nil,
1311
+ timeout: nil,
1312
+ type: nil)
1313
+ ```
1314
+
1315
+
1316
+ Returns the buffer with the captured screenshot.
1317
+
1318
+ ## select_option
1319
+
1320
+ ```
1321
+ def select_option(
1322
+ selector,
1323
+ element: nil,
1324
+ index: nil,
1325
+ value: nil,
1326
+ label: nil,
1327
+ force: nil,
1328
+ noWaitAfter: nil,
1329
+ strict: nil,
1330
+ timeout: nil)
1331
+ ```
1332
+
1333
+
1334
+ This method waits for an element matching `selector`, 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.
1335
+
1336
+ 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.
1337
+
1338
+ Returns the array of option values that have been successfully selected.
1339
+
1340
+ Triggers a `change` and `input` event once all the provided options have been selected.
1341
+
1342
+ **Usage**
1343
+
1344
+ ```ruby
1345
+ # single selection matching the value
1346
+ page.select_option("select#colors", value: "blue")
1347
+ # single selection matching both the label
1348
+ page.select_option("select#colors", label: "blue")
1349
+ # multiple selection
1350
+ page.select_option("select#colors", value: ["red", "green", "blue"])
1351
+ ```
1352
+
1353
+ ## set_checked
1354
+
1355
+ ```
1356
+ def set_checked(
1357
+ selector,
1358
+ checked,
1359
+ force: nil,
1360
+ noWaitAfter: nil,
1361
+ position: nil,
1362
+ strict: nil,
1363
+ timeout: nil,
1364
+ trial: nil)
1365
+ ```
1366
+
1367
+
1368
+ This method checks or unchecks an element matching `selector` by performing the following steps:
1369
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1370
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
1371
+ 1. If the element already has the right checked state, this method returns immediately.
1372
+ 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.
1373
+ 1. Scroll the element into view if needed.
1374
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
1375
+ 1. Ensure that the element is now checked or unchecked. If not, this method throws.
1376
+
1377
+ When all steps combined have not finished during the specified `timeout`, this method throws a
1378
+ `TimeoutError`. Passing zero timeout disables this.
1379
+
1380
+ ## set_content
1381
+
1382
+ ```
1383
+ def set_content(html, timeout: nil, waitUntil: nil)
1384
+ ```
1385
+ alias: `content=`
1386
+
1387
+
1388
+ This method internally calls [document.write()](https://developer.mozilla.org/en-US/docs/Web/API/Document/write), inheriting all its specific characteristics and behaviors.
1389
+
1390
+ ## set_default_navigation_timeout
1391
+
1392
+ ```
1393
+ def set_default_navigation_timeout(timeout)
1394
+ ```
1395
+ alias: `default_navigation_timeout=`
1396
+
1397
+
1398
+ This setting will change the default maximum navigation time for the following methods and related shortcuts:
1399
+ - [Page#go_back](./page#go_back)
1400
+ - [Page#go_forward](./page#go_forward)
1401
+ - [Page#goto](./page#goto)
1402
+ - [Page#reload](./page#reload)
1403
+ - [Page#set_content](./page#set_content)
1404
+ - [Page#expect_navigation](./page#expect_navigation)
1405
+ - [Page#wait_for_url](./page#wait_for_url)
1406
+
1407
+ **NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout) takes priority over [Page#set_default_timeout](./page#set_default_timeout),
1408
+ [BrowserContext#set_default_timeout](./browser_context#set_default_timeout) and [BrowserContext#set_default_navigation_timeout](./browser_context#set_default_navigation_timeout).
1409
+
1410
+ ## set_default_timeout
1411
+
1412
+ ```
1413
+ def set_default_timeout(timeout)
1414
+ ```
1415
+ alias: `default_timeout=`
1416
+
1417
+
1418
+ This setting will change the default maximum time for all the methods accepting `timeout` option.
1419
+
1420
+ **NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout) takes priority over [Page#set_default_timeout](./page#set_default_timeout).
1421
+
1422
+ ## set_extra_http_headers
1423
+
1424
+ ```
1425
+ def set_extra_http_headers(headers)
1426
+ ```
1427
+ alias: `extra_http_headers=`
1428
+
1429
+
1430
+ The extra HTTP headers will be sent with every request the page initiates.
1431
+
1432
+ **NOTE**: [Page#set_extra_http_headers](./page#set_extra_http_headers) does not guarantee the order of headers in the outgoing requests.
1433
+
1434
+ ## set_input_files
1435
+
1436
+ ```
1437
+ def set_input_files(
1438
+ selector,
1439
+ files,
1440
+ noWaitAfter: nil,
1441
+ strict: nil,
1442
+ timeout: nil)
1443
+ ```
1444
+
1445
+
1446
+ Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
1447
+ are resolved relative to the current working directory. For empty array, clears the selected files.
1448
+ For inputs with a `[webkitdirectory]` attribute, only a single directory path is supported.
1449
+
1450
+ This method expects `selector` to point to an
1451
+ [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.
1452
+
1453
+ ## set_viewport_size
1454
+
1455
+ ```
1456
+ def set_viewport_size(viewportSize)
1457
+ ```
1458
+ alias: `viewport_size=`
1459
+
1460
+
1461
+ In the case of multiple pages in a single browser, each page can have its own viewport size. However,
1462
+ [Browser#new_context](./browser#new_context) allows to set viewport size (and more) for all pages in the context at once.
1463
+
1464
+ [Page#set_viewport_size](./page#set_viewport_size) will resize the page. A lot of websites don't expect phones to change size, so you should set the
1465
+ viewport size before navigating to the page. [Page#set_viewport_size](./page#set_viewport_size) will also reset `screen` size, use [Browser#new_context](./browser#new_context) with `screen` and `viewport` parameters if you need better control of these properties.
1466
+
1467
+ **Usage**
1468
+
1469
+ ```ruby
1470
+ page.viewport_size = { width: 640, height: 480 }
1471
+ page.goto("https://example.com")
1472
+ ```
1473
+
1474
+ ## tap_point
1475
+
1476
+ ```
1477
+ def tap_point(
1478
+ selector,
1479
+ force: nil,
1480
+ modifiers: nil,
1481
+ noWaitAfter: nil,
1482
+ position: nil,
1483
+ strict: nil,
1484
+ timeout: nil,
1485
+ trial: nil)
1486
+ ```
1487
+
1488
+
1489
+ This method taps an element matching `selector` by performing the following steps:
1490
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1491
+ 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.
1492
+ 1. Scroll the element into view if needed.
1493
+ 1. Use [Page#touchscreen](./page#touchscreen) to tap the center of the element, or the specified `position`.
1494
+
1495
+ When all steps combined have not finished during the specified `timeout`, this method throws a
1496
+ `TimeoutError`. Passing zero timeout disables this.
1497
+
1498
+ **NOTE**: [Page#tap_point](./page#tap_point) the method will throw if `hasTouch` option of the browser context is false.
1499
+
1500
+ ## text_content
1501
+
1502
+ ```
1503
+ def text_content(selector, strict: nil, timeout: nil)
1504
+ ```
1505
+
1506
+
1507
+ Returns `element.textContent`.
1508
+
1509
+ ## title
1510
+
1511
+ ```
1512
+ def title
1513
+ ```
1514
+
1515
+
1516
+ Returns the page's title.
1517
+
1518
+ ## type
1519
+
1520
+ ```
1521
+ def type(
1522
+ selector,
1523
+ text,
1524
+ delay: nil,
1525
+ noWaitAfter: nil,
1526
+ strict: nil,
1527
+ timeout: nil)
1528
+ ```
1529
+
1530
+ :::warning
1531
+
1532
+ 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).
1533
+
1534
+ :::
1535
+
1536
+
1537
+ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
1538
+ fine-grained keyboard events. To fill values in form fields, use [Page#fill](./page#fill).
1539
+
1540
+ To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
1541
+
1542
+ **Usage**
1543
+
1544
+ ## uncheck
1545
+
1546
+ ```
1547
+ def uncheck(
1548
+ selector,
1549
+ force: nil,
1550
+ noWaitAfter: nil,
1551
+ position: nil,
1552
+ strict: nil,
1553
+ timeout: nil,
1554
+ trial: nil)
1555
+ ```
1556
+
1557
+
1558
+ This method unchecks an element matching `selector` by performing the following steps:
1559
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1560
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already unchecked, this method returns immediately.
1561
+ 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.
1562
+ 1. Scroll the element into view if needed.
1563
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
1564
+ 1. Ensure that the element is now unchecked. If not, this method throws.
1565
+
1566
+ When all steps combined have not finished during the specified `timeout`, this method throws a
1567
+ `TimeoutError`. Passing zero timeout disables this.
1568
+
1569
+ ## unroute_all
1570
+
1571
+ ```
1572
+ def unroute_all(behavior: nil)
1573
+ ```
1574
+
1575
+
1576
+ Removes all routes created with [Page#route](./page#route) and [Page#route_from_har](./page#route_from_har).
1577
+
1578
+ ## unroute
1579
+
1580
+ ```
1581
+ def unroute(url, handler: nil)
1582
+ ```
1583
+
1584
+
1585
+ Removes a route created with [Page#route](./page#route). When `handler` is not specified, removes all routes for
1586
+ the `url`.
1587
+
1588
+ ## url
1589
+
1590
+ ```
1591
+ def url
1592
+ ```
1593
+
1594
+
1595
+
1596
+ ## video
1597
+
1598
+ ```
1599
+ def video
1600
+ ```
1601
+
1602
+
1603
+ Video object associated with this page.
1604
+
1605
+ ## viewport_size
1606
+
1607
+ ```
1608
+ def viewport_size
1609
+ ```
1610
+
1611
+
1612
+
1613
+ ## expect_console_message
1614
+
1615
+ ```
1616
+ def expect_console_message(predicate: nil, timeout: nil, &block)
1617
+ ```
1618
+
1619
+
1620
+ Performs action and waits for a [ConsoleMessage](./console_message) to be logged by in the page. If predicate is provided, it passes
1621
+ [ConsoleMessage](./console_message) value into the `predicate` function and waits for `predicate(message)` to return a truthy value.
1622
+ Will throw an error if the page is closed before the [`event: Page.console`] event is fired.
1623
+
1624
+ ## expect_download
1625
+
1626
+ ```
1627
+ def expect_download(predicate: nil, timeout: nil, &block)
1628
+ ```
1629
+
1630
+
1631
+ Performs action and waits for a new [Download](./download). If predicate is provided, it passes
1632
+ [Download](./download) value into the `predicate` function and waits for `predicate(download)` to return a truthy value.
1633
+ Will throw an error if the page is closed before the download event is fired.
1634
+
1635
+ ## expect_event
1636
+
1637
+ ```
1638
+ def expect_event(event, predicate: nil, timeout: nil, &block)
1639
+ ```
1640
+
1641
+
1642
+ Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1643
+ value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1644
+
1645
+ **Usage**
1646
+
1647
+ ```ruby
1648
+ frame = page.expect_event("framenavigated") do
1649
+ page.get_by_role("button")
1650
+ end
1651
+ ```
1652
+
1653
+ ## expect_file_chooser
1654
+
1655
+ ```
1656
+ def expect_file_chooser(predicate: nil, timeout: nil, &block)
1657
+ ```
1658
+
1659
+
1660
+ Performs action and waits for a new [FileChooser](./file_chooser) to be created. If predicate is provided, it passes
1661
+ [FileChooser](./file_chooser) value into the `predicate` function and waits for `predicate.call(fileChooser)` to return a truthy value.
1662
+ Will throw an error if the page is closed before the file chooser is opened.
1663
+
1664
+ ## wait_for_function
1665
+
1666
+ ```
1667
+ def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
1668
+ ```
1669
+
1670
+
1671
+ Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
1672
+
1673
+ **Usage**
1674
+
1675
+ The [Page#wait_for_function](./page#wait_for_function) can be used to observe viewport size change:
1676
+
1677
+ ```ruby
1678
+ page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1679
+ page.wait_for_function("() => window.x > 0")
1680
+ ```
1681
+
1682
+ To pass an argument to the predicate of [Page#wait_for_function](./page#wait_for_function) function:
1683
+
1684
+ ```ruby
1685
+ selector = ".foo"
1686
+ page.wait_for_function("selector => !!document.querySelector(selector)", arg: selector)
1687
+ ```
1688
+
1689
+ ## wait_for_load_state
1690
+
1691
+ ```
1692
+ def wait_for_load_state(state: nil, timeout: nil)
1693
+ ```
1694
+
1695
+
1696
+ Returns when the required load state has been reached.
1697
+
1698
+ This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
1699
+ when this method is called. If current document has already reached the required state, resolves immediately.
1700
+
1701
+ **NOTE**: Most of the time, this method is not needed because Playwright [auto-waits before every action](https://playwright.dev/python/docs/actionability).
1702
+
1703
+ **Usage**
1704
+
1705
+ ```ruby
1706
+ page.get_by_role("button").click # click triggers navigation.
1707
+ page.wait_for_load_state # the promise resolves after "load" event.
1708
+ ```
1709
+
1710
+ ```ruby
1711
+ popup = page.expect_popup do
1712
+ page.get_by_role("button").click # click triggers a popup.
1713
+ end
1714
+
1715
+ # Wait for the "DOMContentLoaded" event.
1716
+ popup.wait_for_load_state("domcontentloaded")
1717
+ puts popup.title # popup is ready to use.
1718
+ ```
1719
+
1720
+ ## expect_navigation
1721
+
1722
+ ```
1723
+ def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
1724
+ ```
1725
+
1726
+ :::warning
1727
+
1728
+ This method is inherently racy, please use [Page#wait_for_url](./page#wait_for_url) instead.
1729
+
1730
+ :::
1731
+
1732
+
1733
+ Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation
1734
+ will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
1735
+ History API usage, the navigation will resolve with `null`.
1736
+
1737
+ **Usage**
1738
+
1739
+ This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
1740
+ cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
1741
+ Consider this example:
1742
+
1743
+ ```ruby
1744
+ page.expect_navigation do
1745
+ # This action triggers the navigation after a timeout.
1746
+ page.get_by_text("Navigate after timeout").click
1747
+ end # Resolves after navigation has finished
1748
+ ```
1749
+
1750
+ **NOTE**: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered
1751
+ a navigation.
1752
+
1753
+ ## expect_popup
1754
+
1755
+ ```
1756
+ def expect_popup(predicate: nil, timeout: nil, &block)
1757
+ ```
1758
+
1759
+
1760
+ Performs action and waits for a popup [Page](./page). If predicate is provided, it passes
1761
+ [Popup] value into the `predicate` function and waits for `predicate(page)` to return a truthy value.
1762
+ Will throw an error if the page is closed before the popup event is fired.
1763
+
1764
+ ## expect_request
1765
+
1766
+ ```
1767
+ def expect_request(urlOrPredicate, timeout: nil, &block)
1768
+ ```
1769
+
1770
+
1771
+ Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more details about events.
1772
+
1773
+ **Usage**
1774
+
1775
+ ```ruby
1776
+ page.content = '<form action="https://example.com/resource"><input type="submit" value="trigger request" /></form>'
1777
+ request = page.expect_request(/example.com\/resource/) do
1778
+ page.get_by_text("trigger request").click
1779
+ end
1780
+ puts request.headers
1781
+
1782
+ page.wait_for_load_state # wait for request finished.
1783
+
1784
+ # or with a predicate
1785
+ page.content = '<form action="https://example.com/resource"><input type="submit" value="trigger request" /></form>'
1786
+ request = page.expect_request(->(req) { req.url.start_with? 'https://example.com/resource' }) do
1787
+ page.get_by_text("trigger request").click
1788
+ end
1789
+ puts request.headers
1790
+ ```
1791
+
1792
+ ## expect_request_finished
1793
+
1794
+ ```
1795
+ def expect_request_finished(predicate: nil, timeout: nil, &block)
1796
+ ```
1797
+
1798
+
1799
+ Performs action and waits for a [Request](./request) to finish loading. If predicate is provided, it passes
1800
+ [Request](./request) value into the `predicate` function and waits for `predicate(request)` to return a truthy value.
1801
+ Will throw an error if the page is closed before the [`event: Page.requestFinished`] event is fired.
1802
+
1803
+ ## expect_response
1804
+
1805
+ ```
1806
+ def expect_response(urlOrPredicate, timeout: nil, &block)
1807
+ ```
1808
+
1809
+
1810
+ Returns the matched response. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more details about events.
1811
+
1812
+ **Usage**
1813
+
1814
+ ```ruby
1815
+ page.content = '<form action="https://example.com/resource"><input type="submit" value="trigger response" /></form>'
1816
+ response = page.expect_response(/example.com\/resource/) do
1817
+ page.get_by_text("trigger response").click
1818
+ end
1819
+ puts response.body
1820
+ puts response.ok?
1821
+
1822
+ page.wait_for_load_state # wait for request finished.
1823
+
1824
+ # or with a predicate
1825
+ page.content = '<form action="https://example.com/resource"><input type="submit" value="trigger response" /></form>'
1826
+ response = page.expect_response(->(res) { res.url.start_with? 'https://example.com/resource' }) do
1827
+ page.get_by_text("trigger response").click
1828
+ end
1829
+ puts response.body
1830
+ puts response.ok?
1831
+ ```
1832
+
1833
+ ## wait_for_selector
1834
+
1835
+ ```
1836
+ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
1837
+ ```
1838
+
1839
+
1840
+ Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
1841
+ `detached`.
1842
+
1843
+ **NOTE**: Playwright automatically waits for element to be ready before performing an action. Using
1844
+ [Locator](./locator) objects and web-first assertions makes the code wait-for-selector-free.
1845
+
1846
+ Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become
1847
+ visible/hidden). If at the moment of calling the method `selector` already satisfies the condition, the method
1848
+ will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the
1849
+ function will throw.
1850
+
1851
+ **Usage**
1852
+
1853
+ This method works across navigations:
1854
+
1855
+ ```ruby
1856
+ %w[https://playwright.dev/ https://playwright-ruby-client.vercel.app/].each do |current_url|
1857
+ page.goto(current_url, waitUntil: "domcontentloaded")
1858
+ element = page.wait_for_selector("img")
1859
+ puts "Loaded image: #{element["src"]}"
1860
+ end
1861
+ ```
1862
+
1863
+ ## wait_for_timeout
1864
+
1865
+ ```
1866
+ def wait_for_timeout(timeout)
1867
+ ```
1868
+
1869
+
1870
+ Waits for the given `timeout` in milliseconds.
1871
+
1872
+ Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
1873
+ flaky. Use signals such as network events, selectors becoming visible and others instead.
1874
+
1875
+ **Usage**
1876
+
1877
+ ```ruby
1878
+ page.wait_for_timeout(1000)
1879
+ ```
1880
+
1881
+ ## wait_for_url
1882
+
1883
+ ```
1884
+ def wait_for_url(url, timeout: nil, waitUntil: nil)
1885
+ ```
1886
+
1887
+
1888
+ Waits for the main frame to navigate to the given URL.
1889
+
1890
+ **Usage**
1891
+
1892
+ ```ruby
1893
+ page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1894
+ page.wait_for_url("**/target.html")
1895
+ ```
1896
+
1897
+ ## expect_websocket
1898
+
1899
+ ```
1900
+ def expect_websocket(predicate: nil, timeout: nil, &block)
1901
+ ```
1902
+
1903
+
1904
+ Performs action and waits for a new [WebSocket](./web_socket). If predicate is provided, it passes
1905
+ [WebSocket](./web_socket) value into the `predicate` function and waits for `predicate(webSocket)` to return a truthy value.
1906
+ Will throw an error if the page is closed before the WebSocket event is fired.
1907
+
1908
+ ## expect_worker
1909
+
1910
+ ```
1911
+ def expect_worker(predicate: nil, timeout: nil, &block)
1912
+ ```
1913
+
1914
+
1915
+ Performs action and waits for a new [Worker](./worker). If predicate is provided, it passes
1916
+ [Worker](./worker) value into the `predicate` function and waits for `predicate(worker)` to return a truthy value.
1917
+ Will throw an error if the page is closed before the worker event is fired.
1918
+
1919
+ ## workers
1920
+
1921
+ ```
1922
+ def workers
1923
+ ```
1924
+
1925
+
1926
+ This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
1927
+ associated with the page.
1928
+
1929
+ **NOTE**: This does not contain ServiceWorkers
1930
+
1931
+ ## clock
1932
+
1933
+
1934
+ Playwright has ability to mock clock and passage of time.
1935
+
1936
+ ## keyboard
1937
+
1938
+ ## mouse
1939
+
1940
+ ## request
1941
+
1942
+
1943
+ API testing helper associated with this page. This method returns the same instance as
1944
+ [BrowserContext#request](./browser_context#request) on the page's context. See [BrowserContext#request](./browser_context#request) for more details.
1945
+
1946
+ ## touchscreen