playwright-ruby-client 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/browser.md +2 -0
  3. data/documentation/docs/api/browser_context.md +2 -3
  4. data/documentation/docs/api/dialog.md +15 -18
  5. data/documentation/docs/api/element_handle.md +28 -50
  6. data/documentation/docs/api/experimental/android_device.md +1 -0
  7. data/documentation/docs/api/file_chooser.md +4 -5
  8. data/documentation/docs/api/frame.md +3 -4
  9. data/documentation/docs/api/js_handle.md +11 -14
  10. data/documentation/docs/api/page.md +163 -230
  11. data/documentation/docs/api/worker.md +18 -1
  12. data/documentation/docs/include/api_coverage.md +3 -1
  13. data/lib/playwright/channel_owners/binding_call.rb +1 -1
  14. data/lib/playwright/channel_owners/page.rb +6 -6
  15. data/lib/playwright/channel_owners/worker.rb +4 -0
  16. data/lib/playwright/playwright_api.rb +16 -1
  17. data/lib/playwright/version.rb +1 -1
  18. data/lib/playwright_api/android.rb +6 -6
  19. data/lib/playwright_api/android_device.rb +8 -7
  20. data/lib/playwright_api/browser.rb +10 -8
  21. data/lib/playwright_api/browser_context.rb +11 -12
  22. data/lib/playwright_api/browser_type.rb +7 -6
  23. data/lib/playwright_api/console_message.rb +6 -6
  24. data/lib/playwright_api/dialog.rb +6 -6
  25. data/lib/playwright_api/element_handle.rb +6 -6
  26. data/lib/playwright_api/frame.rb +6 -6
  27. data/lib/playwright_api/js_handle.rb +6 -6
  28. data/lib/playwright_api/page.rb +32 -18
  29. data/lib/playwright_api/playwright.rb +6 -6
  30. data/lib/playwright_api/request.rb +6 -6
  31. data/lib/playwright_api/response.rb +8 -8
  32. data/lib/playwright_api/route.rb +6 -6
  33. data/lib/playwright_api/selectors.rb +6 -6
  34. data/lib/playwright_api/worker.rb +22 -0
  35. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b365f47558ade3fcf3d803a070cbd61eb4eae6279f0d93c1641a53d9b50ec232
4
- data.tar.gz: 353de7a190205c6d3d4542b3058afe24c0c634fe70811c15384b55d1cb464571
3
+ metadata.gz: 623dc9bf11ce77bda6cd9006c727e31060564810bac0ccf5f06aabffc5976c07
4
+ data.tar.gz: 206995c24a6cbd4dcd6867eaa076e3b3052b7a7056cd63188a7ebb0e54c38056
5
5
  SHA512:
6
- metadata.gz: ec905a5051716af754993c11b5a484e5bf69a9b50cdb6681f583869d0cf70d23eb3265507d6739b6d006fc8419360dea8570f6fae6fc3ac8fdd6d44ae3547fd8
7
- data.tar.gz: cf06e3351a40457108080dea85af6c8e417ffda3bec6671f9280ad42bc5fde7e58cf039016fe11387a7cb3e1347e1391f1440d23c2e54e512ca70e39ba90db38
6
+ metadata.gz: a341d042e6e35b5205f56303efda6fe9a34e857c12696622c366f0ebbc113816b3418e05e87b8fe60867ae2252964a36545b8bd782cf61f9c23f42e868cb098a
7
+ data.tar.gz: 68fc458f0fc750c208f8daa7f900ef33977987aa6684db4edea20c42cf5f3837deb4e5b828385fd9c25d11769ff1b345cdb795aef370158bd009a515dfeeb54d
@@ -85,6 +85,7 @@ def new_context(
85
85
  record_har_path: nil,
86
86
  record_video_dir: nil,
87
87
  record_video_size: nil,
88
+ reducedMotion: nil,
88
89
  screen: nil,
89
90
  storageState: nil,
90
91
  timezoneId: nil,
@@ -132,6 +133,7 @@ def new_page(
132
133
  record_har_path: nil,
133
134
  record_video_dir: nil,
134
135
  record_video_size: nil,
136
+ reducedMotion: nil,
135
137
  screen: nil,
136
138
  storageState: nil,
137
139
  timezoneId: nil,
@@ -131,8 +131,7 @@ The method adds a function called `name` on the `window` object of every frame i
131
131
  called, the 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`. If
132
132
  the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
133
133
 
134
- The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
135
- page: Page, frame: Frame }`.
134
+ The first argument of the `callback` function contains information about the caller: `{ browser_context: BrowserContext, page: Page, frame: Frame }`.
136
135
 
137
136
  See [Page#expose_binding](./page#expose_binding) for page-only version.
138
137
 
@@ -193,7 +192,7 @@ If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/W
193
192
 
194
193
  See [Page#expose_function](./page#expose_function) for page-only version.
195
194
 
196
- An example of adding an `sha256` function to all pages in the context:
195
+ An example of adding a `sha256` function to all pages in the context:
197
196
 
198
197
  ```ruby
199
198
  require 'digest'
@@ -8,24 +8,21 @@ sidebar_position: 10
8
8
 
9
9
  An example of using [Dialog](./dialog) class:
10
10
 
11
- ```python sync title=example_c954c35627e62be69e1f138f25d7377b13e18d08039d476946217827fa95db52.py
12
- from playwright.sync_api import sync_playwright
13
-
14
- def handle_dialog(dialog):
15
- print(dialog.message)
16
- dialog.dismiss()
17
-
18
- def run(playwright):
19
- chromium = playwright.chromium
20
- browser = chromium.launch()
21
- page = browser.new_page()
22
- page.on("dialog", handle_dialog)
23
- page.evaluate("alert('1')")
24
- browser.close()
25
-
26
- with sync_playwright() as playwright:
27
- run(playwright)
28
-
11
+ ```ruby
12
+ def handle_dialog(dialog)
13
+ puts "[#{dialog.type}] #{dialog.message}"
14
+ if dialog.message =~ /foo/
15
+ dialog.accept_async
16
+ else
17
+ dialog.dismiss
18
+ end
19
+ end
20
+
21
+ page.on("dialog", method(:handle_dialog))
22
+ page.evaluate("confirm('foo')") # will be accepted
23
+ # => [confirm] foo
24
+ page.evaluate("alert('bar')") # will be dismissed
25
+ # => [alert] bar
29
26
  ```
30
27
 
31
28
  > NOTE: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener. When listener is
@@ -9,21 +9,11 @@ sidebar_position: 10
9
9
  ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page#query_selector](./page#query_selector)
10
10
  method.
11
11
 
12
- ```python sync title=example_5ba38bdc5d9e5ce7cfc9c8841eb0176efbb4690d18962066f9ee67f1e8b7b050.py
13
- from playwright.sync_api import sync_playwright
14
-
15
- def run(playwright):
16
- chromium = playwright.chromium
17
- browser = chromium.launch()
18
- page = browser.new_page()
19
- page.goto("https://example.com")
20
- href_element = page.query_selector("a")
21
- href_element.click()
22
- # ...
23
-
24
- with sync_playwright() as playwright:
25
- run(playwright)
26
-
12
+ ```ruby
13
+ page.goto("https://example.com")
14
+ href_element = page.query_selector("a")
15
+ href_element.click
16
+ # ...
27
17
  ```
28
18
 
29
19
  ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
@@ -51,10 +41,12 @@ Elements from child frames return the bounding box relative to the main frame, u
51
41
  Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
52
42
  snippet should click the center of the element.
53
43
 
54
- ```python sync title=example_8382aa7cfb42a9a17e348e2f738279f1bd9a038f1ea35cc3cb244cc64d768f93.py
55
- box = element_handle.bounding_box()
56
- page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
57
-
44
+ ```ruby
45
+ box = element_handle.bounding_box
46
+ page.mouse.click(
47
+ box["x"] + box["width"] / 2,
48
+ box["y"] + box["height"] / 2,
49
+ )
58
50
  ```
59
51
 
60
52
 
@@ -156,9 +148,8 @@ The snippet below dispatches the `click` event on the element. Regardless of the
156
148
  `click` is dispatched. This is equivalent to calling
157
149
  [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
158
150
 
159
- ```python sync title=example_3b86add6ce355082cd43f4ac0ba9e69c15960bbd7ca601d0618355fe53aa8902.py
151
+ ```ruby
160
152
  element_handle.dispatch_event("click")
161
-
162
153
  ```
163
154
 
164
155
  Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
@@ -175,11 +166,10 @@ Since `eventInit` is event-specific, please refer to the events documentation fo
175
166
 
176
167
  You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
177
168
 
178
- ```python sync title=example_6b70ea4cf0c7ae9c82cf0ed22ab0dbbb563e2d1419b35d04aa513cf91f0856f9.py
169
+ ```ruby
179
170
  # note you can only create data_transfer in chromium and firefox
180
171
  data_transfer = page.evaluate_handle("new DataTransfer()")
181
- element_handle.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
182
-
172
+ element_handle.dispatch_event("dragstart", eventInit: { dataTransfer: data_transfer })
183
173
  ```
184
174
 
185
175
 
@@ -201,11 +191,10 @@ and return its value.
201
191
 
202
192
  Examples:
203
193
 
204
- ```python sync title=example_f6a83ec555fcf23877c11cf55f02a8c89a7fc11d3324859feda42e592e129f4f.py
194
+ ```ruby
205
195
  tweet_handle = page.query_selector(".tweet")
206
- assert tweet_handle.eval_on_selector(".like", "node => node.innerText") == "100"
207
- assert tweet_handle.eval_on_selector(".retweets", "node => node.innerText") = "10"
208
-
196
+ tweet_handle.eval_on_selector(".like", "node => node.innerText") # => "100"
197
+ tweet_handle.eval_on_selector(".retweets", "node => node.innerText") # => "10"
209
198
  ```
210
199
 
211
200
 
@@ -233,10 +222,9 @@ Examples:
233
222
  </div>
234
223
  ```
235
224
 
236
- ```python sync title=example_11b54bf5ec18a0d0ceee0868651bb41ab5cd3afcc6b20d5c44f90d835c8d6f81.py
225
+ ```ruby
237
226
  feed_handle = page.query_selector(".feed")
238
- assert feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") == ["hello!", "hi!"]
239
-
227
+ feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") # => ["hello!", "hi!"]
240
228
  ```
241
229
 
242
230
 
@@ -463,26 +451,18 @@ Returns the array of option values that have been successfully selected.
463
451
 
464
452
  Triggers a `change` and `input` event once all the provided options have been selected.
465
453
 
466
- ```python sync title=example_dc2ce38846b91d234483ed8b915b785ffbd9403213279465acd6605f314fe736.py
454
+ ```ruby
467
455
  # single selection matching the value
468
- handle.select_option("blue")
456
+ element_handle.select_option(value: "blue")
469
457
  # single selection matching both the label
470
- handle.select_option(label="blue")
458
+ element_handle.select_option(label: "blue")
471
459
  # multiple selection
472
- handle.select_option(value=["red", "green", "blue"])
473
-
460
+ element_handle.select_option(value: ["red", "green", "blue"])
474
461
  ```
475
462
 
476
- ```python sync title=example_b4cdd4a1a4d0392c2d430e0fb5fc670df2d728b6907553650690a2d0377662e4.py
477
- # single selection matching the value
478
- handle.select_option("blue")
479
- # single selection matching both the value and the label
480
- handle.select_option(label="blue")
481
- # multiple selection
482
- handle.select_option("red", "green", "blue")
463
+ ```ruby
483
464
  # multiple selection for blue, red and second option
484
- handle.select_option(value="blue", { index: 2 }, "red")
485
-
465
+ element_handle.select_option(value: "blue", index: 2, label: "red")
486
466
  ```
487
467
 
488
468
 
@@ -552,19 +532,17 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`
552
532
 
553
533
  To press a special key, like `Control` or `ArrowDown`, use [ElementHandle#press](./element_handle#press).
554
534
 
555
- ```python sync title=example_2dc9720467640fd8bc581ed65159742e51ff91b209cb176fef8b95f14eaad54e.py
535
+ ```ruby
556
536
  element_handle.type("hello") # types instantly
557
- element_handle.type("world", delay=100) # types slower, like a user
558
-
537
+ element_handle.type("world", delay: 100) # types slower, like a user
559
538
  ```
560
539
 
561
540
  An example of typing into a text field and then submitting the form:
562
541
 
563
- ```python sync title=example_d13faaf53454653ce45371b5cf337082a82bf7bbb0aada7e97f47d14963bd6b0.py
542
+ ```ruby
564
543
  element_handle = page.query_selector("input")
565
544
  element_handle.type("some text")
566
545
  element_handle.press("Enter")
567
-
568
546
  ```
569
547
 
570
548
 
@@ -47,6 +47,7 @@ def launch_browser(
47
47
  record_har_path: nil,
48
48
  record_video_dir: nil,
49
49
  record_video_size: nil,
50
+ reducedMotion: nil,
50
51
  screen: nil,
51
52
  timezoneId: nil,
52
53
  userAgent: nil,
@@ -6,12 +6,11 @@ sidebar_position: 10
6
6
 
7
7
  [FileChooser](./file_chooser) objects are dispatched by the page in the [`event: Page.fileChooser`] event.
8
8
 
9
- ```python sync title=example_371975841dd417527a865b1501e3a8ba40f905b895cf3317ca90d9890e980843.py
10
- with page.expect_file_chooser() as fc_info:
11
- page.click("upload")
12
- file_chooser = fc_info.value
9
+ ```ruby
10
+ file_chooser = page.expect_file_chooser do
11
+ page.click("upload") # action to trigger file uploading
12
+ end
13
13
  file_chooser.set_files("myfile.pdf")
14
-
15
14
  ```
16
15
 
17
16
 
@@ -308,9 +308,8 @@ a_window_handle # handle for the window object.
308
308
 
309
309
  A string can also be passed in instead of a function.
310
310
 
311
- ```python sync title=example_9daa37cfd3d747c9360d9544f64786bf49d291a6887b0efccc813215b62ae4c6.py
311
+ ```ruby
312
312
  a_handle = page.evaluate_handle("document") # handle for the "document"
313
-
314
313
  ```
315
314
 
316
315
  [JSHandle](./js_handle) instances can be passed as an argument to the [Frame#evaluate_handle](./frame#evaluate_handle):
@@ -318,8 +317,8 @@ a_handle = page.evaluate_handle("document") # handle for the "document"
318
317
  ```ruby
319
318
  body_handle = page.evaluate_handle("document.body")
320
319
  result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
321
- puts result_handle.json_value()
322
- result_handle.dispose()
320
+ puts result_handle.json_value
321
+ result_handle.dispose
323
322
  ```
324
323
 
325
324
 
@@ -7,10 +7,9 @@ sidebar_position: 10
7
7
  JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page#evaluate_handle](./page#evaluate_handle)
8
8
  method.
9
9
 
10
- ```python sync title=example_c408a96b8ac9c9bd54d915009c8b477eb75b7bf9e879fd76b32f3d4b6340a667.py
10
+ ```ruby
11
11
  window_handle = page.evaluate_handle("window")
12
12
  # ...
13
-
14
13
  ```
15
14
 
16
15
  JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with
@@ -50,10 +49,9 @@ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web
50
49
 
51
50
  Examples:
52
51
 
53
- ```python sync title=example_2400f96eaaed3bc6ef6b0a16ba48e83d38a166c7d55a5dba0025472cffc6f2be.py
52
+ ```ruby
54
53
  tweet_handle = page.query_selector(".tweet .retweets")
55
- assert tweet_handle.evaluate("node => node.innerText") == "10 retweets"
56
-
54
+ tweet_handle.evaluate("node => node.innerText") # => "10 retweets"
57
55
  ```
58
56
 
59
57
 
@@ -68,10 +66,10 @@ Returns the return value of `expression` as a [JSHandle](./js_handle).
68
66
 
69
67
  This method passes this handle as the first argument to `expression`.
70
68
 
71
- The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns
69
+ The only difference between [JSHandle#evaluate](./js_handle#evaluate) and [JSHandle#evaluate_handle](./js_handle#evaluate_handle) is that [JSHandle#evaluate_handle](./js_handle#evaluate_handle) returns
72
70
  [JSHandle](./js_handle).
73
71
 
74
- If the function passed to the `jsHandle.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then `jsHandle.evaluateHandle` would wait
72
+ If the function passed to the [JSHandle#evaluate_handle](./js_handle#evaluate_handle) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [JSHandle#evaluate_handle](./js_handle#evaluate_handle) would wait
75
73
  for the promise to resolve and return its value.
76
74
 
77
75
  See [Page#evaluate_handle](./page#evaluate_handle) for more details.
@@ -85,13 +83,12 @@ alias: `properties`
85
83
 
86
84
  The method returns a map with **own property names** as keys and JSHandle instances for the property values.
87
85
 
88
- ```python sync title=example_8292f0e8974d97d20be9bb303d55ccd2d50e42f954e0ada4958ddbef2c6c2977.py
89
- handle = page.evaluate_handle("{window, document}")
90
- properties = handle.get_properties()
91
- window_handle = properties.get("window")
92
- document_handle = properties.get("document")
93
- handle.dispose()
94
-
86
+ ```ruby
87
+ page.goto('https://example.com/')
88
+ window_handle = page.evaluate_handle("window")
89
+ properties = window_handle.properties
90
+ puts properties
91
+ window_handle.dispose
95
92
  ```
96
93
 
97
94
 
@@ -224,9 +224,9 @@ The snippet below dispatches the `click` event on the element. Regardless of the
224
224
  `click` is dispatched. This is equivalent to calling
225
225
  [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
226
226
 
227
- ```python sync title=example_9220b94fd2fa381ab91448dcb551e2eb9806ad331c83454a710f4d8a280990e8.py
227
+ ```ruby
228
+ page.content = '<button id="submit">Send</button>'
228
229
  page.dispatch_event("button#submit", "click")
229
-
230
230
  ```
231
231
 
232
232
  Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
@@ -243,11 +243,12 @@ Since `eventInit` is event-specific, please refer to the events documentation fo
243
243
 
244
244
  You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
245
245
 
246
- ```python sync title=example_9b4482b7243b7ce304d6ce8454395e23db30f3d1d83229242ab7bd2abd5b72e0.py
246
+ ```ruby
247
+ page.content = '<div id="source">Drag</div>'
248
+
247
249
  # note you can only create data_transfer in chromium and firefox
248
250
  data_transfer = page.evaluate_handle("new DataTransfer()")
249
- page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
250
-
251
+ page.dispatch_event("#source", "dragstart", eventInit: { dataTransfer: data_transfer })
251
252
  ```
252
253
 
253
254
 
@@ -255,40 +256,30 @@ page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
255
256
  ## emulate_media
256
257
 
257
258
  ```
258
- def emulate_media(colorScheme: nil, media: nil)
259
+ def emulate_media(colorScheme: nil, media: nil, reducedMotion: nil)
259
260
  ```
260
261
 
261
262
  This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media
262
263
  feature, using the `colorScheme` argument.
263
264
 
264
- ```python sync title=example_df304caf6c61f6f44b3e2b0006a7e05552362a47b17c9ba227df76e918d88a5c.py
265
- page.evaluate("matchMedia('screen').matches")
266
- # True
267
- page.evaluate("matchMedia('print').matches")
268
- # → False
269
-
270
- page.emulate_media(media="print")
271
- page.evaluate("matchMedia('screen').matches")
272
- # → False
273
- page.evaluate("matchMedia('print').matches")
274
- # → True
265
+ ```ruby
266
+ page.evaluate("matchMedia('screen').matches") # => true
267
+ page.evaluate("matchMedia('print').matches") # => false
275
268
 
276
- page.emulate_media()
277
- page.evaluate("matchMedia('screen').matches")
278
- # True
279
- page.evaluate("matchMedia('print').matches")
280
- # → False
269
+ page.emulate_media(media: "print")
270
+ page.evaluate("matchMedia('screen').matches") # => false
271
+ page.evaluate("matchMedia('print').matches") # => true
281
272
 
273
+ page.emulate_media
274
+ page.evaluate("matchMedia('screen').matches") # => true
275
+ page.evaluate("matchMedia('print').matches") # => false
282
276
  ```
283
277
 
284
- ```python sync title=example_f0479a2ee8d8f51dab94f48b7e121cade07e5026d4f602521cc6ccc47feb5a98.py
285
- page.emulate_media(color_scheme="dark")
286
- page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
287
- # True
288
- page.evaluate("matchMedia('(prefers-color-scheme: light)').matches")
289
- # → False
290
- page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
291
-
278
+ ```ruby
279
+ page.emulate_media(colorScheme="dark")
280
+ page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches") # => true
281
+ page.evaluate("matchMedia('(prefers-color-scheme: light)').matches") # => false
282
+ page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") # => false
292
283
  ```
293
284
 
294
285
 
@@ -370,7 +361,7 @@ puts page.evaluate("1 + #{x}") # => "11"
370
361
  ```ruby
371
362
  body_handle = page.query_selector("body")
372
363
  html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", arg: [body_handle, "hello"])
373
- body_handle.dispose()
364
+ body_handle.dispose
374
365
  ```
375
366
 
376
367
  Shortcut for main frame's [Frame#evaluate](./frame#evaluate).
@@ -389,17 +380,15 @@ The only difference between [Page#evaluate](./page#evaluate) and [Page#evaluate_
389
380
  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)
390
381
  would wait for the promise to resolve and return its value.
391
382
 
392
- ```python sync title=example_6802829f93cc4da7e67f3886b9773c7b84054afa84251add50704f8ca6837138.py
383
+ ```ruby
393
384
  a_window_handle = page.evaluate_handle("Promise.resolve(window)")
394
385
  a_window_handle # handle for the window object.
395
-
396
386
  ```
397
387
 
398
388
  A string can also be passed in instead of a function:
399
389
 
400
- ```python sync title=example_9daa37cfd3d747c9360d9544f64786bf49d291a6887b0efccc813215b62ae4c6.py
390
+ ```ruby
401
391
  a_handle = page.evaluate_handle("document") # handle for the "document"
402
-
403
392
  ```
404
393
 
405
394
  [JSHandle](./js_handle) instances can be passed as an argument to the [Page#evaluate_handle](./page#evaluate_handle):
@@ -407,8 +396,8 @@ a_handle = page.evaluate_handle("document") # handle for the "document"
407
396
  ```ruby
408
397
  body_handle = page.evaluate_handle("document.body")
409
398
  result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
410
- puts result_handle.json_value()
411
- result_handle.dispose()
399
+ puts result_handle.json_value
400
+ result_handle.dispose
412
401
  ```
413
402
 
414
403
 
@@ -423,8 +412,7 @@ The method adds a function called `name` on the `window` object of every frame i
423
412
  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`. If the `callback` returns
424
413
  a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
425
414
 
426
- The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
427
- page: Page, frame: Frame }`.
415
+ The first argument of the `callback` function contains information about the caller: `{ browser_context: BrowserContext, page: Page, frame: Frame }`.
428
416
 
429
417
  See [BrowserContext#expose_binding](./browser_context#expose_binding) for the context-wide version.
430
418
 
@@ -432,46 +420,39 @@ See [BrowserContext#expose_binding](./browser_context#expose_binding) for the co
432
420
 
433
421
  An example of exposing page URL to all frames in a page:
434
422
 
435
- ```python sync title=example_551f5963351bfd7141fa8c94f5f22c305ec1c01d617861953374e9290929a551.py
436
- from playwright.sync_api import sync_playwright
437
-
438
- def run(playwright):
439
- webkit = playwright.webkit
440
- browser = webkit.launch(headless=false)
441
- context = browser.new_context()
442
- page = context.new_page()
443
- page.expose_binding("pageURL", lambda source: source["page"].url)
444
- page.set_content("""
445
- <script>
446
- async function onClick() {
447
- document.querySelector('div').textContent = await window.pageURL();
448
- }
449
- </script>
450
- <button onclick="onClick()">Click me</button>
451
- <div></div>
452
- """)
453
- page.click("button")
454
-
455
- with sync_playwright() as playwright:
456
- run(playwright)
457
-
423
+ ```ruby
424
+ page.expose_binding("pageURL", ->(source) { source[:page].url })
425
+ page.content = <<~HTML
426
+ <script>
427
+ async function onClick() {
428
+ document.querySelector('div').textContent = await window.pageURL();
429
+ }
430
+ </script>
431
+ <button onclick="onClick()">Click me</button>
432
+ <div></div>
433
+ HTML
434
+ page.click("button")
458
435
  ```
459
436
 
460
437
  An example of passing an element handle:
461
438
 
462
- ```python sync title=example_6534a792e99e05b5644cea6e5b77ca5d864675a3012f447f0f8318c4fa6a6a54.py
463
- def print(source, element):
464
- print(element.text_content())
439
+ ```ruby
440
+ def print_text(source, element)
441
+ element.text_content
442
+ end
465
443
 
466
- page.expose_binding("clicked", print, handle=true)
467
- page.set_content("""
468
- <script>
469
- document.addEventListener('click', event => window.clicked(event.target));
470
- </script>
471
- <div>Click me</div>
472
- <div>Or click me</div>
473
- """)
444
+ page.expose_binding("clicked", method(:print_text), handle: true)
445
+ page.content = <<~HTML
446
+ <script>
447
+ document.addEventListener('click', async (event) => {
448
+ alert(await window.clicked(event.target));
449
+ })
450
+ </script>
451
+ <div>Click me</div>
452
+ <div>Or click me</div>
453
+ HTML
474
454
 
455
+ page.click('div')
475
456
  ```
476
457
 
477
458
 
@@ -491,37 +472,26 @@ See [BrowserContext#expose_function](./browser_context#expose_function) for cont
491
472
 
492
473
  > NOTE: Functions installed via [Page#expose_function](./page#expose_function) survive navigations.
493
474
 
494
- An example of adding an `sha1` function to the page:
495
-
496
- ```python sync title=example_496ab45e0c5f4c47869f66c2b738fbd9eef0ef4065fa923caf9c929e50e14c21.py
497
- import hashlib
498
- from playwright.sync_api import sync_playwright
475
+ An example of adding a `sha256` function to the page:
499
476
 
500
- def sha1(text):
501
- m = hashlib.sha1()
502
- m.update(bytes(text, "utf8"))
503
- return m.hexdigest()
504
-
505
-
506
- def run(playwright):
507
- webkit = playwright.webkit
508
- browser = webkit.launch(headless=False)
509
- page = browser.new_page()
510
- page.expose_function("sha1", sha1)
511
- page.set_content("""
512
- <script>
513
- async function onClick() {
514
- document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
515
- }
516
- </script>
517
- <button onclick="onClick()">Click me</button>
518
- <div></div>
519
- """)
520
- page.click("button")
477
+ ```ruby
478
+ require 'digest'
521
479
 
522
- with sync_playwright() as playwright:
523
- run(playwright)
480
+ def sha1(text)
481
+ Digest::SHA256.hexdigest(text)
482
+ end
524
483
 
484
+ page.expose_function("sha256", method(:sha256))
485
+ page.content = <<~HTML
486
+ <script>
487
+ async function onClick() {
488
+ document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
489
+ }
490
+ </script>
491
+ <button onclick="onClick()">Click me</button>
492
+ <div></div>
493
+ HTML
494
+ page.click("button")
525
495
  ```
526
496
 
527
497
 
@@ -564,14 +534,12 @@ def frame(name: nil, url: nil)
564
534
 
565
535
  Returns frame matching the specified criteria. Either `name` or `url` must be specified.
566
536
 
567
- ```py title=example_034f224ec0f7b4d98fdf875cefbc7e6c8726a6d615cbba9b1cb8c49180fd7d69.py
568
- frame = page.frame(name="frame-name")
569
-
537
+ ```ruby
538
+ frame = page.frame(name: "frame-name")
570
539
  ```
571
540
 
572
- ```py title=example_a8a4717d8505a35662faafa9e6c2cfbbc0a44755c8e4d43252f882b7e4f1f04a.py
573
- frame = page.frame(url=r".*domain.*")
574
-
541
+ ```ruby
542
+ frame = page.frame(url: /.*domain.*/)
575
543
  ```
576
544
 
577
545
 
@@ -786,11 +754,10 @@ Returns the PDF buffer.
786
754
  [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
787
755
  force rendering of exact colors.
788
756
 
789
- ```python sync title=example_e079fbec8ee0607ee45cdca94df61dea36f7fd3840986d5f4ac24918569a5f5e.py
757
+ ```ruby
790
758
  # generates a pdf with "screen" media type.
791
- page.emulate_media(media="screen")
792
- page.pdf(path="page.pdf")
793
-
759
+ page.emulate_media(media: "screen")
760
+ page.pdf(path: "page.pdf")
794
761
  ```
795
762
 
796
763
  The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels.
@@ -852,17 +819,14 @@ texts.
852
819
  Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
853
820
  modifier, modifier is pressed and being held while the subsequent key is being pressed.
854
821
 
855
- ```python sync title=example_aa4598bd7dbeb8d2f8f5c0aa3bdc84042eb396de37b49f8ff8c1ea39f080f709.py
856
- page = browser.new_page()
822
+ ```ruby
857
823
  page.goto("https://keycode.info")
858
824
  page.press("body", "A")
859
- page.screenshot(path="a.png")
825
+ page.screenshot(path: "a.png")
860
826
  page.press("body", "ArrowLeft")
861
- page.screenshot(path="arrow_left.png")
827
+ page.screenshot(path: "arrow_left.png")
862
828
  page.press("body", "Shift+O")
863
- page.screenshot(path="o.png")
864
- browser.close()
865
-
829
+ page.screenshot(path: "o.png")
866
830
  ```
867
831
 
868
832
 
@@ -912,35 +876,31 @@ Once routing is enabled, every request matching the url pattern will stall unles
912
876
 
913
877
  An example of a naive handler that aborts all image requests:
914
878
 
915
- ```python sync title=example_a3038a6fd55b06cb841251877bf6eb781b08018695514c6e0054848d4e93d345.py
916
- page = browser.new_page()
917
- page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
879
+ ```ruby
880
+ page.route("**/*.{png,jpg,jpeg}", ->(route, request) { route.abort })
918
881
  page.goto("https://example.com")
919
- browser.close()
920
-
921
882
  ```
922
883
 
923
884
  or the same snippet using a regex pattern instead:
924
885
 
925
- ```python sync title=example_7fda2a761bdd66b942415ab444c6b4bb89dd87ec0f0a4a03e6775feb694f7913.py
926
- page = browser.new_page()
927
- page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
886
+ ```ruby
887
+ page.route(/\.(png|jpg)$/, ->(route, request) { route.abort })
928
888
  page.goto("https://example.com")
929
- browser.close()
930
-
931
889
  ```
932
890
 
933
891
  It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
934
892
  post data, and leaving all other requests as is:
935
893
 
936
- ```python sync title=example_ff4fba1273c7e65f4d68b4fcdd9dc4b792bba435005f0b9e7066ca18ded750b5.py
937
- def handle_route(route):
938
- if ("my-string" in route.request.post_data)
939
- route.fulfill(body="mocked-data")
894
+ ```ruby
895
+ def handle_route(route, request)
896
+ if request.post_data["my-string"]
897
+ mocked_data = request.post_data.merge({ "my-string" => 'mocked-data'})
898
+ route.fulfill(postData: mocked_data)
940
899
  else
941
- route.continue_()
942
- page.route("/api/**", handle_route)
943
-
900
+ route.continue
901
+ end
902
+ end
903
+ page.route("/api/**", method(:handle_route))
944
904
  ```
945
905
 
946
906
  Page routes take precedence over browser context routes (set up with [BrowserContext#route](./browser_context#route)) when request
@@ -989,14 +949,13 @@ Returns the array of option values that have been successfully selected.
989
949
 
990
950
  Triggers a `change` and `input` event once all the provided options have been selected.
991
951
 
992
- ```python sync title=example_4b17eb65721c55859c50eb12b4ee762e65408618cf3b7d07958b68d60ea6be6c.py
952
+ ```ruby
993
953
  # single selection matching the value
994
- page.select_option("select#colors", "blue")
954
+ page.select_option("select#colors", value: "blue")
995
955
  # single selection matching both the label
996
- page.select_option("select#colors", label="blue")
956
+ page.select_option("select#colors", label: "blue")
997
957
  # multiple selection
998
- page.select_option("select#colors", value=["red", "green", "blue"])
999
-
958
+ page.select_option("select#colors", value: ["red", "green", "blue"])
1000
959
  ```
1001
960
 
1002
961
  Shortcut for main frame's [Frame#select_option](./frame#select_option).
@@ -1076,11 +1035,9 @@ In the case of multiple pages in a single browser, each page can have its own vi
1076
1035
  `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1077
1036
  viewport size before navigating to the page.
1078
1037
 
1079
- ```python sync title=example_e3883d51c0785c34b62633fe311c4f1252dd9f29e6b4b6c7719f1eb74384e6e9.py
1080
- page = browser.new_page()
1081
- page.set_viewport_size({"width": 640, "height": 480})
1038
+ ```ruby
1039
+ page.viewport_size = { width: 640, height: 480 }
1082
1040
  page.goto("https://example.com")
1083
-
1084
1041
  ```
1085
1042
 
1086
1043
 
@@ -1145,10 +1102,9 @@ fine-grained keyboard events. To fill values in form fields, use [Page#fill](./p
1145
1102
 
1146
1103
  To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
1147
1104
 
1148
- ```python sync title=example_4c7291f6023d2fe4f957cb7727646b50fdee40275db330a6f4517e349ea7f916.py
1105
+ ```ruby
1149
1106
  page.type("#mytextarea", "hello") # types instantly
1150
- page.type("#mytextarea", "world", delay=100) # types slower, like a user
1151
-
1107
+ page.type("#mytextarea", "world", delay: 100) # types slower, like a user
1152
1108
  ```
1153
1109
 
1154
1110
  Shortcut for main frame's [Frame#type](./frame#type).
@@ -1221,7 +1177,7 @@ def expect_console_message(predicate: nil, timeout: nil, &block)
1221
1177
 
1222
1178
  Performs action and waits for a [ConsoleMessage](./console_message) to be logged by in the page. If predicate is provided, it passes
1223
1179
  [ConsoleMessage](./console_message) value into the `predicate` function and waits for `predicate(message)` to return a truthy value. Will
1224
- throw an error if the page is closed before the console event is fired.
1180
+ throw an error if the page is closed before the [`event: Page.console`] event is fired.
1225
1181
 
1226
1182
  ## expect_download
1227
1183
 
@@ -1242,15 +1198,13 @@ def expect_event(event, predicate: nil, timeout: nil, &block)
1242
1198
  Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1243
1199
  value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1244
1200
 
1245
- ```python sync title=example_1b007e0db5f2b594b586367be3b56f9eb9b928740efbceada2c60cb7794592d4.py
1246
- with page.expect_event("framenavigated") as event_info:
1247
- page.click("button")
1248
- frame = event_info.value
1249
-
1201
+ ```ruby
1202
+ frame = page.expect_event("framenavigated") do
1203
+ page.click("button")
1204
+ end
1250
1205
  ```
1251
1206
 
1252
1207
 
1253
-
1254
1208
  ## expect_file_chooser
1255
1209
 
1256
1210
  ```
@@ -1258,7 +1212,7 @@ def expect_file_chooser(predicate: nil, timeout: nil, &block)
1258
1212
  ```
1259
1213
 
1260
1214
  Performs action and waits for a new [FileChooser](./file_chooser) to be created. If predicate is provided, it passes [FileChooser](./file_chooser) value
1261
- into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an error if
1215
+ into the `predicate` function and waits for `predicate.call(fileChooser)` to return a truthy value. Will throw an error if
1262
1216
  the page is closed before the file chooser is opened.
1263
1217
 
1264
1218
  ## wait_for_function
@@ -1271,28 +1225,16 @@ Returns when the `expression` returns a truthy value. It resolves to a JSHandle
1271
1225
 
1272
1226
  The [Page#wait_for_function](./page#wait_for_function) can be used to observe viewport size change:
1273
1227
 
1274
- ```python sync title=example_e50869c913bec2f0a89a22ff1c438128c3c8f2e3710acb10665445cf52e3ec73.py
1275
- from playwright.sync_api import sync_playwright
1276
-
1277
- def run(playwright):
1278
- webkit = playwright.webkit
1279
- browser = webkit.launch()
1280
- page = browser.new_page()
1281
- page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1282
- page.wait_for_function("() => window.x > 0")
1283
- browser.close()
1284
-
1285
- with sync_playwright() as playwright:
1286
- run(playwright)
1287
-
1228
+ ```ruby
1229
+ page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1230
+ page.wait_for_function("() => window.x > 0")
1288
1231
  ```
1289
1232
 
1290
1233
  To pass an argument to the predicate of [Page#wait_for_function](./page#wait_for_function) function:
1291
1234
 
1292
- ```python sync title=example_04c93558dde8de62944515a8ed91fda6e0d01feca4d3bb2e58c6fda10a8c6ade.py
1235
+ ```ruby
1293
1236
  selector = ".foo"
1294
- page.wait_for_function("selector => !!document.querySelector(selector)", selector)
1295
-
1237
+ page.wait_for_function("selector => !!document.querySelector(selector)", arg: selector)
1296
1238
  ```
1297
1239
 
1298
1240
  Shortcut for main frame's [Frame#wait_for_function](./frame#wait_for_function).
@@ -1308,20 +1250,19 @@ Returns when the required load state has been reached.
1308
1250
  This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
1309
1251
  when this method is called. If current document has already reached the required state, resolves immediately.
1310
1252
 
1311
- ```python sync title=example_cd35fb085612055231ddf97f68bc5331b4620914e0686b889f2cd4061836cff8.py
1253
+ ```ruby
1312
1254
  page.click("button") # click triggers navigation.
1313
- page.wait_for_load_state() # the promise resolves after "load" event.
1314
-
1255
+ page.wait_for_load_state # the promise resolves after "load" event.
1315
1256
  ```
1316
1257
 
1317
- ```python sync title=example_51ba8a745d5093516e9a50482d8bf3ce29afe507ca5cfe89f4a0e35963f52a36.py
1318
- with page.expect_popup() as page_info:
1319
- page.click("button") # click triggers a popup.
1320
- popup = page_info.value
1321
- # Following resolves after "domcontentloaded" event.
1322
- popup.wait_for_load_state("domcontentloaded")
1323
- print(popup.title()) # popup is ready to use.
1258
+ ```ruby
1259
+ popup = page.expect_popup do
1260
+ page.click("button") # click triggers a popup.
1261
+ end
1324
1262
 
1263
+ # Following resolves after "domcontentloaded" event.
1264
+ popup.wait_for_load_state("domcontentloaded")
1265
+ puts popup.title # popup is ready to use.
1325
1266
  ```
1326
1267
 
1327
1268
  Shortcut for main frame's [Frame#wait_for_load_state](./frame#wait_for_load_state).
@@ -1340,17 +1281,16 @@ This resolves when the page navigates to a new URL or reloads. It is useful for
1340
1281
  cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
1341
1282
  Consider this example:
1342
1283
 
1343
- ```python sync title=example_bc5a01f756c1275b9942c4b3e50a9f1748c04da8d5f8f697567b9d04806ec0dc.py
1344
- with page.expect_navigation():
1345
- page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1346
- # Resolves after navigation has finished
1347
-
1284
+ ```ruby
1285
+ page.expect_navigation do
1286
+ page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1287
+ end # Resolves after navigation has finished
1348
1288
  ```
1349
1289
 
1350
1290
  > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
1351
1291
  considered a navigation.
1352
1292
 
1353
- Shortcut for main frame's [`method: Frame.waitForNavigation`].
1293
+ Shortcut for main frame's [Frame#expect_navigation](./frame#expect_navigation).
1354
1294
 
1355
1295
  ## expect_popup
1356
1296
 
@@ -1358,29 +1298,32 @@ Shortcut for main frame's [`method: Frame.waitForNavigation`].
1358
1298
  def expect_popup(predicate: nil, timeout: nil, &block)
1359
1299
  ```
1360
1300
 
1361
- Performs action and waits for a popup [Page](./page). If predicate is provided, it passes [Popup] value into the `predicate`
1362
- function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is closed before the
1363
- popup event is fired.
1301
+ Performs action and waits for a popup [Page](./page). If predicate is provided, it passes popup [Page](./page) value into the predicate function and waits for `predicate.call(page)` to return a truthy value. Will throw an error if the page is closed before the popup event is fired.
1364
1302
 
1365
1303
  ## expect_request
1366
1304
 
1367
1305
  ```
1368
- def expect_request(urlOrPredicate, timeout: nil)
1306
+ def expect_request(urlOrPredicate, timeout: nil, &block)
1369
1307
  ```
1370
1308
 
1371
1309
  Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events) for more details
1372
1310
  about events.
1373
1311
 
1374
- ```python sync title=example_9246912bc386c2f9310662279b12200ae131f724a1ec1ca99e511568767cb9c8.py
1375
- with page.expect_request("http://example.com/resource") as first:
1376
- page.click('button')
1377
- first_request = first.value
1312
+ ```ruby
1313
+ page.content = '<form action="https://example.com/resource"><input type="submit" /></form>'
1314
+ request = page.expect_request(/example.com\/resource/) do
1315
+ page.click("input")
1316
+ end
1317
+ puts request.headers
1378
1318
 
1379
- # or with a lambda
1380
- with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
1381
- page.click('img')
1382
- second_request = second.value
1319
+ page.wait_for_load_state # wait for request finished.
1383
1320
 
1321
+ # or with a predicate
1322
+ page.content = '<form action="https://example.com/resource"><input type="submit" /></form>'
1323
+ request = page.expect_request(->(req) { req.url.start_with? 'https://example.com/resource' }) do
1324
+ page.click("input")
1325
+ end
1326
+ puts request.headers
1384
1327
  ```
1385
1328
 
1386
1329
 
@@ -1388,23 +1331,24 @@ second_request = second.value
1388
1331
  ## expect_response
1389
1332
 
1390
1333
  ```
1391
- def expect_response(urlOrPredicate, timeout: nil)
1334
+ def expect_response(urlOrPredicate, timeout: nil, &block)
1392
1335
  ```
1393
1336
 
1394
1337
  Returns the matched response. See [waiting for event](https://playwright.dev/python/docs/events) for more details about events.
1395
1338
 
1396
- ```python sync title=example_d2a76790c0bb59bf5ae2f41d1a29b50954412136de3699ec79dc33cdfd56004b.py
1397
- with page.expect_response("https://example.com/resource") as response_info:
1398
- page.click("input")
1399
- response = response_info.value
1400
- return response.ok
1401
-
1402
- # or with a lambda
1403
- with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
1404
- page.click("input")
1405
- response = response_info.value
1406
- return response.ok
1339
+ ```ruby
1340
+ page.content = '<form action="https://example.com/resource"><input type="submit" /></form>'
1341
+ response = page.expect_response(/example.com\/resource/) do
1342
+ page.click("input")
1343
+ end
1344
+ puts response.body
1407
1345
 
1346
+ # or with a predicate
1347
+ page.content = '<form action="https://example.com/resource"><input type="submit" /></form>'
1348
+ response = page.expect_response(->(res) { res.url.start_with? 'https://example.com/resource' }) do
1349
+ page.click("input")
1350
+ end
1351
+ puts response.body
1408
1352
  ```
1409
1353
 
1410
1354
 
@@ -1424,22 +1368,12 @@ selector doesn't satisfy the condition for the `timeout` milliseconds, the funct
1424
1368
 
1425
1369
  This method works across navigations:
1426
1370
 
1427
- ```python sync title=example_0a62ff34b0d31a64dd1597b9dff456e4139b36207d26efdec7109e278dc315a3.py
1428
- from playwright.sync_api import sync_playwright
1429
-
1430
- def run(playwright):
1431
- chromium = playwright.chromium
1432
- browser = chromium.launch()
1433
- page = browser.new_page()
1434
- for current_url in ["https://google.com", "https://bbc.com"]:
1435
- page.goto(current_url, wait_until="domcontentloaded")
1436
- element = page.wait_for_selector("img")
1437
- print("Loaded image: " + str(element.get_attribute("src")))
1438
- browser.close()
1439
-
1440
- with sync_playwright() as playwright:
1441
- run(playwright)
1442
-
1371
+ ```ruby
1372
+ %w[https://google.com https://bbc.com].each do |current_url|
1373
+ page.goto(current_url, waitUntil: "domcontentloaded")
1374
+ element = page.wait_for_selector("img")
1375
+ puts "Loaded image: #{element["src"]}"
1376
+ end
1443
1377
  ```
1444
1378
 
1445
1379
 
@@ -1452,10 +1386,9 @@ def wait_for_url(url, timeout: nil, waitUntil: nil)
1452
1386
 
1453
1387
  Waits for the main frame to navigate to the given URL.
1454
1388
 
1455
- ```python sync title=example_a49b1deed2b93fe358b57bca9c4032f44b3d24436a78720421ba040aad4d661c.py
1389
+ ```ruby
1456
1390
  page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1457
1391
  page.wait_for_url("**/target.html")
1458
-
1459
1392
  ```
1460
1393
 
1461
1394
  Shortcut for main frame's [Frame#wait_for_url](./frame#wait_for_url).