playwright-ruby-client 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/README.md +33 -0
  3. data/documentation/babel.config.js +3 -0
  4. data/documentation/docs/api/accessibility.md +7 -0
  5. data/documentation/docs/api/browser.md +185 -0
  6. data/documentation/docs/api/browser_context.md +398 -0
  7. data/documentation/docs/api/browser_type.md +105 -0
  8. data/documentation/docs/api/cdp_session.md +7 -0
  9. data/documentation/docs/api/console_message.md +41 -0
  10. data/documentation/docs/api/dialog.md +74 -0
  11. data/documentation/docs/api/element_handle.md +640 -0
  12. data/documentation/docs/api/experimental/_category_.yml +3 -0
  13. data/documentation/docs/api/experimental/android.md +25 -0
  14. data/documentation/docs/api/experimental/android_device.md +91 -0
  15. data/documentation/docs/api/experimental/android_input.md +38 -0
  16. data/documentation/docs/api/experimental/android_socket.md +7 -0
  17. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  18. data/documentation/docs/api/file_chooser.md +51 -0
  19. data/documentation/docs/api/frame.md +867 -0
  20. data/documentation/docs/api/js_handle.md +116 -0
  21. data/documentation/docs/api/keyboard.md +157 -0
  22. data/documentation/docs/api/mouse.md +69 -0
  23. data/documentation/docs/api/page.md +1469 -0
  24. data/documentation/docs/api/playwright.md +63 -0
  25. data/documentation/docs/api/request.md +188 -0
  26. data/documentation/docs/api/response.md +97 -0
  27. data/documentation/docs/api/route.md +80 -0
  28. data/documentation/docs/api/selectors.md +23 -0
  29. data/documentation/docs/api/touchscreen.md +8 -0
  30. data/documentation/docs/api/tracing.md +54 -0
  31. data/documentation/docs/api/web_socket.md +7 -0
  32. data/documentation/docs/api/worker.md +7 -0
  33. data/documentation/docs/article/api_coverage.mdx +11 -0
  34. data/documentation/docs/article/getting_started.md +152 -0
  35. data/documentation/docs/article/guides/_category_.yml +3 -0
  36. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  37. data/documentation/docs/article/guides/launch_browser.md +119 -0
  38. data/documentation/docs/article/guides/rails_integration.md +51 -0
  39. data/{docs → documentation/docs/include}/api_coverage.md +0 -0
  40. data/documentation/docusaurus.config.js +107 -0
  41. data/documentation/package.json +39 -0
  42. data/documentation/sidebars.js +15 -0
  43. data/documentation/src/components/HomepageFeatures.js +61 -0
  44. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  45. data/documentation/src/css/custom.css +44 -0
  46. data/documentation/src/pages/index.js +50 -0
  47. data/documentation/src/pages/index.module.css +41 -0
  48. data/documentation/src/pages/markdown-page.md +7 -0
  49. data/documentation/static/.nojekyll +0 -0
  50. data/documentation/static/img/playwright-logo.svg +9 -0
  51. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  52. data/documentation/static/img/undraw_web_development.svg +1 -0
  53. data/documentation/static/img/undraw_windows.svg +1 -0
  54. data/documentation/yarn.lock +8805 -0
  55. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  56. data/lib/playwright/channel_owners/browser_context.rb +2 -2
  57. data/lib/playwright/channel_owners/element_handle.rb +2 -10
  58. data/lib/playwright/channel_owners/frame.rb +6 -28
  59. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  60. data/lib/playwright/channel_owners/page.rb +10 -1
  61. data/lib/playwright/input_files.rb +0 -8
  62. data/lib/playwright/javascript.rb +0 -10
  63. data/lib/playwright/javascript/expression.rb +2 -7
  64. data/lib/playwright/version.rb +1 -1
  65. data/lib/playwright_api/accessibility.rb +7 -89
  66. data/lib/playwright_api/android.rb +7 -64
  67. data/lib/playwright_api/android_device.rb +8 -8
  68. data/lib/playwright_api/browser.rb +15 -169
  69. data/lib/playwright_api/browser_context.rb +47 -609
  70. data/lib/playwright_api/browser_type.rb +13 -103
  71. data/lib/playwright_api/cdp_session.rb +2 -25
  72. data/lib/playwright_api/console_message.rb +6 -6
  73. data/lib/playwright_api/dialog.rb +11 -92
  74. data/lib/playwright_api/element_handle.rb +60 -362
  75. data/lib/playwright_api/file_chooser.rb +0 -28
  76. data/lib/playwright_api/frame.rb +74 -713
  77. data/lib/playwright_api/js_handle.rb +16 -90
  78. data/lib/playwright_api/keyboard.rb +21 -213
  79. data/lib/playwright_api/mouse.rb +1 -45
  80. data/lib/playwright_api/page.rb +155 -1635
  81. data/lib/playwright_api/playwright.rb +14 -117
  82. data/lib/playwright_api/request.rb +15 -121
  83. data/lib/playwright_api/response.rb +9 -9
  84. data/lib/playwright_api/route.rb +8 -105
  85. data/lib/playwright_api/selectors.rb +6 -97
  86. data/lib/playwright_api/tracing.rb +1 -61
  87. data/lib/playwright_api/web_socket.rb +1 -1
  88. data/lib/playwright_api/worker.rb +6 -42
  89. metadata +55 -4
  90. data/lib/playwright/javascript/function.rb +0 -67
@@ -1,40 +1,12 @@
1
1
  module Playwright
2
2
  # `FileChooser` objects are dispatched by the page in the [`event: Page.fileChooser`] event.
3
- #
4
3
  #
5
- # ```js
6
- # const [fileChooser] = await Promise.all([
7
- # page.waitForEvent('filechooser'),
8
- # page.click('upload')
9
- # ]);
10
- # await fileChooser.setFiles('myfile.pdf');
11
- # ```
12
- #
13
- # ```java
14
- # FileChooser fileChooser = page.waitForFileChooser(() -> page.click("upload"));
15
- # fileChooser.setFiles(Paths.get("myfile.pdf"));
16
- # ```
17
- #
18
- # ```python async
19
- # async with page.expect_file_chooser() as fc_info:
20
- # await page.click("upload")
21
- # file_chooser = await fc_info.value
22
- # await file_chooser.set_files("myfile.pdf")
23
- # ```
24
- #
25
4
  # ```python sync
26
5
  # with page.expect_file_chooser() as fc_info:
27
6
  # page.click("upload")
28
7
  # file_chooser = fc_info.value
29
8
  # file_chooser.set_files("myfile.pdf")
30
9
  # ```
31
- #
32
- # ```csharp
33
- # var waitForFileChooserTask = page.WaitForFileChooserAsync();
34
- # await page.ClickAsync("upload");
35
- # var fileChooser = await waitForFileChooserTask;
36
- # await fileChooser.SetFilesAsync("temp.txt");
37
- # ```
38
10
  class FileChooser < PlaywrightApi
39
11
 
40
12
  # Returns input element associated with this file chooser.
@@ -1,85 +1,19 @@
1
1
  module Playwright
2
2
  # At every point of time, page exposes its current frame tree via the [`method: Page.mainFrame`] and
3
3
  # [`method: Frame.childFrames`] methods.
4
- #
4
+ #
5
5
  # `Frame` object's lifecycle is controlled by three events, dispatched on the page object:
6
6
  # - [`event: Page.frameAttached`] - fired when the frame gets attached to the page. A Frame can be attached to the page
7
7
  # only once.
8
8
  # - [`event: Page.frameNavigated`] - fired when the frame commits navigation to a different URL.
9
9
  # - [`event: Page.frameDetached`] - fired when the frame gets detached from the page. A Frame can be detached from the
10
10
  # page only once.
11
- #
11
+ #
12
12
  # An example of dumping frame tree:
13
- #
14
13
  #
15
- # ```js
16
- # const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
17
- #
18
- # (async () => {
19
- # const browser = await firefox.launch();
20
- # const page = await browser.newPage();
21
- # await page.goto('https://www.google.com/chrome/browser/canary.html');
22
- # dumpFrameTree(page.mainFrame(), '');
23
- # await browser.close();
24
- #
25
- # function dumpFrameTree(frame, indent) {
26
- # console.log(indent + frame.url());
27
- # for (const child of frame.childFrames()) {
28
- # dumpFrameTree(child, indent + ' ');
29
- # }
30
- # }
31
- # })();
32
- # ```
33
- #
34
- # ```java
35
- # import com.microsoft.playwright.*;
36
- #
37
- # public class Example {
38
- # public static void main(String[] args) {
39
- # try (Playwright playwright = Playwright.create()) {
40
- # BrowserType firefox = playwright.firefox();
41
- # Browser browser = firefox.launch();
42
- # Page page = browser.newPage();
43
- # page.navigate("https://www.google.com/chrome/browser/canary.html");
44
- # dumpFrameTree(page.mainFrame(), "");
45
- # browser.close();
46
- # }
47
- # }
48
- # static void dumpFrameTree(Frame frame, String indent) {
49
- # System.out.println(indent + frame.url());
50
- # for (Frame child : frame.childFrames()) {
51
- # dumpFrameTree(child, indent + " ");
52
- # }
53
- # }
54
- # }
55
- # ```
56
- #
57
- # ```python async
58
- # import asyncio
59
- # from playwright.async_api import async_playwright
60
- #
61
- # async def run(playwright):
62
- # firefox = playwright.firefox
63
- # browser = await firefox.launch()
64
- # page = await browser.new_page()
65
- # await page.goto("https://www.theverge.com")
66
- # dump_frame_tree(page.main_frame, "")
67
- # await browser.close()
68
- #
69
- # def dump_frame_tree(frame, indent):
70
- # print(indent + frame.name + '@' + frame.url)
71
- # for child in frame.child_frames:
72
- # dump_frame_tree(child, indent + " ")
73
- #
74
- # async def main():
75
- # async with async_playwright() as playwright:
76
- # await run(playwright)
77
- # asyncio.run(main())
78
- # ```
79
- #
80
14
  # ```python sync
81
15
  # from playwright.sync_api import sync_playwright
82
- #
16
+ #
83
17
  # def run(playwright):
84
18
  # firefox = playwright.firefox
85
19
  # browser = firefox.launch()
@@ -87,52 +21,26 @@ module Playwright
87
21
  # page.goto("https://www.theverge.com")
88
22
  # dump_frame_tree(page.main_frame, "")
89
23
  # browser.close()
90
- #
24
+ #
91
25
  # def dump_frame_tree(frame, indent):
92
26
  # print(indent + frame.name + '@' + frame.url)
93
27
  # for child in frame.child_frames:
94
28
  # dump_frame_tree(child, indent + " ")
95
- #
29
+ #
96
30
  # with sync_playwright() as playwright:
97
31
  # run(playwright)
98
32
  # ```
99
- #
100
- # ```csharp
101
- # using Microsoft.Playwright;
102
- # using System;
103
- # using System.Threading.Tasks;
104
- #
105
- # class FrameExamples
106
- # {
107
- # public static async Task Main()
108
- # {
109
- # using var playwright = await Playwright.CreateAsync();
110
- # await using var browser = await playwright.Firefox.LaunchAsync();
111
- # var page = await browser.NewPageAsync();
112
- #
113
- # await page.GotoAsync("https://www.bing.com");
114
- # DumpFrameTree(page.MainFrame, string.Empty);
115
- # }
116
- #
117
- # private static void DumpFrameTree(IFrame frame, string indent)
118
- # {
119
- # Console.WriteLine($"{indent}{frame.Url}");
120
- # foreach (var child in frame.ChildFrames)
121
- # DumpFrameTree(child, indent + " ");
122
- # }
123
- # }
124
- # ```
125
33
  class Frame < PlaywrightApi
126
34
 
127
35
  # Returns the added tag when the script's onload fires or when the script content was injected into frame.
128
- #
36
+ #
129
37
  # Adds a `<script>` tag into the page with the desired url or content.
130
38
  def add_script_tag(content: nil, path: nil, type: nil, url: nil)
131
39
  wrap_impl(@impl.add_script_tag(content: unwrap_impl(content), path: unwrap_impl(path), type: unwrap_impl(type), url: unwrap_impl(url)))
132
40
  end
133
41
 
134
42
  # Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
135
- #
43
+ #
136
44
  # Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
137
45
  # content.
138
46
  def add_style_tag(content: nil, path: nil, url: nil)
@@ -149,7 +57,7 @@ module Playwright
149
57
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
150
58
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
151
59
  # 1. Ensure that the element is now checked. If not, this method throws.
152
- #
60
+ #
153
61
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
154
62
  # zero timeout disables this.
155
63
  def check(
@@ -173,7 +81,7 @@ module Playwright
173
81
  # 1. Scroll the element into view if needed.
174
82
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
175
83
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
176
- #
84
+ #
177
85
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
178
86
  # zero timeout disables this.
179
87
  def click(
@@ -203,10 +111,10 @@ module Playwright
203
111
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
204
112
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
205
113
  # first click of the `dblclick()` triggers a navigation event, this method will throw.
206
- #
114
+ #
207
115
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
208
116
  # zero timeout disables this.
209
- #
117
+ #
210
118
  # > NOTE: `frame.dblclick()` dispatches two `click` events and a single `dblclick` event.
211
119
  def dblclick(
212
120
  selector,
@@ -224,31 +132,14 @@ module Playwright
224
132
  # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
225
133
  # `click` is dispatched. This is equivalent to calling
226
134
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
227
- #
228
135
  #
229
- # ```js
230
- # await frame.dispatchEvent('button#submit', 'click');
231
- # ```
232
- #
233
- # ```java
234
- # frame.dispatchEvent("button#submit", "click");
235
- # ```
236
- #
237
- # ```python async
238
- # await frame.dispatch_event("button#submit", "click")
239
- # ```
240
- #
241
136
  # ```python sync
242
137
  # frame.dispatch_event("button#submit", "click")
243
138
  # ```
244
- #
245
- # ```csharp
246
- # await frame.DispatchEventAsync("button#submit", "click");
247
- # ```
248
- #
139
+ #
249
140
  # Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
250
141
  # and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
251
- #
142
+ #
252
143
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
253
144
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
254
145
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
@@ -257,320 +148,115 @@ module Playwright
257
148
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
258
149
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
259
150
  # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
260
- #
151
+ #
261
152
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
262
- #
263
153
  #
264
- # ```js
265
- # // Note you can only create DataTransfer in Chromium and Firefox
266
- # const dataTransfer = await frame.evaluateHandle(() => new DataTransfer());
267
- # await frame.dispatchEvent('#source', 'dragstart', { dataTransfer });
268
- # ```
269
- #
270
- # ```java
271
- # // Note you can only create DataTransfer in Chromium and Firefox
272
- # JSHandle dataTransfer = frame.evaluateHandle("() => new DataTransfer()");
273
- # Map<String, Object> arg = new HashMap<>();
274
- # arg.put("dataTransfer", dataTransfer);
275
- # frame.dispatchEvent("#source", "dragstart", arg);
276
- # ```
277
- #
278
- # ```python async
279
- # # note you can only create data_transfer in chromium and firefox
280
- # data_transfer = await frame.evaluate_handle("new DataTransfer()")
281
- # await frame.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
282
- # ```
283
- #
284
154
  # ```python sync
285
155
  # # note you can only create data_transfer in chromium and firefox
286
156
  # data_transfer = frame.evaluate_handle("new DataTransfer()")
287
157
  # frame.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
288
158
  # ```
289
- #
290
- # ```csharp
291
- # // Note you can only create DataTransfer in Chromium and Firefox
292
- # var dataTransfer = await frame.EvaluateHandleAsync("() => new DataTransfer()");
293
- # await frame.DispatchEventAsync("#source", "dragstart", new { dataTransfer });
294
- # ```
295
159
  def dispatch_event(selector, type, eventInit: nil, timeout: nil)
296
160
  wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
297
161
  end
298
162
 
299
163
  # Returns the return value of `expression`.
300
- #
164
+ #
301
165
  # The method finds an element matching the specified selector within the frame and passes it as a first argument to
302
166
  # `expression`. See [Working with selectors](./selectors.md) for more details. If no elements match the selector, the
303
167
  # method throws an error.
304
- #
168
+ #
305
169
  # If `expression` returns a [Promise], then [`method: Frame.evalOnSelector`] would wait for the promise to resolve and
306
170
  # return its value.
307
- #
171
+ #
308
172
  # Examples:
309
- #
310
173
  #
311
- # ```js
312
- # const searchValue = await frame.$eval('#search', el => el.value);
313
- # const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
314
- # const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
315
- # ```
316
- #
317
- # ```java
318
- # String searchValue = (String) frame.evalOnSelector("#search", "el => el.value");
319
- # String preloadHref = (String) frame.evalOnSelector("link[rel=preload]", "el => el.href");
320
- # String html = (String) frame.evalOnSelector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
321
- # ```
322
- #
323
- # ```python async
324
- # search_value = await frame.eval_on_selector("#search", "el => el.value")
325
- # preload_href = await frame.eval_on_selector("link[rel=preload]", "el => el.href")
326
- # html = await frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
327
- # ```
328
- #
329
174
  # ```python sync
330
175
  # search_value = frame.eval_on_selector("#search", "el => el.value")
331
176
  # preload_href = frame.eval_on_selector("link[rel=preload]", "el => el.href")
332
177
  # html = frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
333
178
  # ```
334
- #
335
- # ```csharp
336
- # var searchValue = await frame.EvalOnSelectorAsync<string>("#search", "el => el.value");
337
- # var preloadHref = await frame.EvalOnSelectorAsync<string>("link[rel=preload]", "el => el.href");
338
- # var html = await frame.EvalOnSelectorAsync(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
339
- # ```
340
179
  def eval_on_selector(selector, expression, arg: nil)
341
180
  wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
342
181
  end
343
182
 
344
183
  # Returns the return value of `expression`.
345
- #
184
+ #
346
185
  # The method finds all elements matching the specified selector within the frame and passes an array of matched elements
347
186
  # as a first argument to `expression`. See [Working with selectors](./selectors.md) for more details.
348
- #
187
+ #
349
188
  # If `expression` returns a [Promise], then [`method: Frame.evalOnSelectorAll`] would wait for the promise to resolve and
350
189
  # return its value.
351
- #
190
+ #
352
191
  # Examples:
353
- #
354
192
  #
355
- # ```js
356
- # const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
357
- # ```
358
- #
359
- # ```java
360
- # boolean divsCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
361
- # ```
362
- #
363
- # ```python async
364
- # divs_counts = await frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
365
- # ```
366
- #
367
193
  # ```python sync
368
194
  # divs_counts = frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
369
195
  # ```
370
- #
371
- # ```csharp
372
- # var divsCount = await frame.EvalOnSelectorAllAsync<bool>("div", "(divs, min) => divs.length >= min", 10);
373
- # ```
374
196
  def eval_on_selector_all(selector, expression, arg: nil)
375
197
  wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
376
198
  end
377
199
 
378
200
  # Returns the return value of `expression`.
379
- #
201
+ #
380
202
  # If the function passed to the [`method: Frame.evaluate`] returns a [Promise], then [`method: Frame.evaluate`] would wait
381
203
  # for the promise to resolve and return its value.
382
- #
204
+ #
383
205
  # If the function passed to the [`method: Frame.evaluate`] returns a non-[Serializable] value, then
384
206
  # [`method: Frame.evaluate`] returns `undefined`. Playwright also supports transferring some additional values that are
385
207
  # not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
386
- #
387
208
  #
388
- # ```js
389
- # const result = await frame.evaluate(([x, y]) => {
390
- # return Promise.resolve(x * y);
391
- # }, [7, 8]);
392
- # console.log(result); // prints "56"
393
- # ```
394
- #
395
- # ```java
396
- # Object result = frame.evaluate("([x, y]) => {\n" +
397
- # " return Promise.resolve(x * y);\n" +
398
- # "}", Arrays.asList(7, 8));
399
- # System.out.println(result); // prints "56"
400
- # ```
401
- #
402
- # ```python async
403
- # result = await frame.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
404
- # print(result) # prints "56"
405
- # ```
406
- #
407
209
  # ```python sync
408
210
  # result = frame.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
409
211
  # print(result) # prints "56"
410
212
  # ```
411
- #
412
- # ```csharp
413
- # var result = await frame.EvaluateAsync<int>("([x, y]) => Promise.resolve(x * y)", new[] { 7, 8 });
414
- # Console.WriteLine(result);
415
- # ```
416
- #
213
+ #
417
214
  # A string can also be passed in instead of a function.
418
- #
419
215
  #
420
- # ```js
421
- # console.log(await frame.evaluate('1 + 2')); // prints "3"
422
- # ```
423
- #
424
- # ```java
425
- # System.out.println(frame.evaluate("1 + 2")); // prints "3"
426
- # ```
427
- #
428
- # ```python async
429
- # print(await frame.evaluate("1 + 2")) # prints "3"
430
- # x = 10
431
- # print(await frame.evaluate(f"1 + {x}")) # prints "11"
432
- # ```
433
- #
434
216
  # ```python sync
435
217
  # print(frame.evaluate("1 + 2")) # prints "3"
436
218
  # x = 10
437
219
  # print(frame.evaluate(f"1 + {x}")) # prints "11"
438
220
  # ```
439
- #
440
- # ```csharp
441
- # Console.WriteLine(await frame.EvaluateAsync<int>("1 + 2")); // prints "3"
442
- # ```
443
- #
221
+ #
444
222
  # `ElementHandle` instances can be passed as an argument to the [`method: Frame.evaluate`]:
445
- #
446
223
  #
447
- # ```js
448
- # const bodyHandle = await frame.$('body');
449
- # const html = await frame.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
450
- # await bodyHandle.dispose();
451
- # ```
452
- #
453
- # ```java
454
- # ElementHandle bodyHandle = frame.querySelector("body");
455
- # String html = (String) frame.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
456
- # bodyHandle.dispose();
457
- # ```
458
- #
459
- # ```python async
460
- # body_handle = await frame.query_selector("body")
461
- # html = await frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
462
- # await body_handle.dispose()
463
- # ```
464
- #
465
224
  # ```python sync
466
225
  # body_handle = frame.query_selector("body")
467
226
  # html = frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
468
227
  # body_handle.dispose()
469
228
  # ```
470
- #
471
- # ```csharp
472
- # var bodyHandle = await frame.QuerySelectorAsync("body");
473
- # var html = await frame.EvaluateAsync<string>("([body, suffix]) => body.innerHTML + suffix", new object [] { bodyHandle, "hello" });
474
- # await bodyHandle.DisposeAsync();
475
- # ```
476
229
  def evaluate(expression, arg: nil)
477
230
  wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
478
231
  end
479
232
 
480
233
  # Returns the return value of `expression` as a `JSHandle`.
481
- #
234
+ #
482
235
  # The only difference between [`method: Frame.evaluate`] and [`method: Frame.evaluateHandle`] is that
483
236
  # [`method: Frame.evaluateHandle`] returns `JSHandle`.
484
- #
237
+ #
485
238
  # If the function, passed to the [`method: Frame.evaluateHandle`], returns a [Promise], then
486
239
  # [`method: Frame.evaluateHandle`] would wait for the promise to resolve and return its value.
487
- #
488
240
  #
489
- # ```js
490
- # const aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window));
491
- # aWindowHandle; // Handle for the window object.
492
- # ```
493
- #
494
- # ```java
495
- # // Handle for the window object.
496
- # JSHandle aWindowHandle = frame.evaluateHandle("() => Promise.resolve(window)");
497
- # ```
498
- #
499
- # ```python async
500
- # a_window_handle = await frame.evaluate_handle("Promise.resolve(window)")
501
- # a_window_handle # handle for the window object.
502
- # ```
503
- #
504
241
  # ```python sync
505
242
  # a_window_handle = frame.evaluate_handle("Promise.resolve(window)")
506
243
  # a_window_handle # handle for the window object.
507
244
  # ```
508
- #
509
- # ```csharp
510
- # // Handle for the window object.
511
- # var aWindowHandle = await frame.EvaluateHandleAsync("() => Promise.resolve(window)");
512
- # ```
513
- #
245
+ #
514
246
  # A string can also be passed in instead of a function.
515
- #
516
247
  #
517
- # ```js
518
- # const aHandle = await frame.evaluateHandle('document'); // Handle for the 'document'.
519
- # ```
520
- #
521
- # ```java
522
- # JSHandle aHandle = frame.evaluateHandle("document"); // Handle for the "document".
523
- # ```
524
- #
525
- # ```python async
526
- # a_handle = await page.evaluate_handle("document") # handle for the "document"
527
- # ```
528
- #
529
248
  # ```python sync
530
249
  # a_handle = page.evaluate_handle("document") # handle for the "document"
531
250
  # ```
532
- #
533
- # ```csharp
534
- # var docHandle = await frame.EvalueHandleAsync("document"); // Handle for the `document`
535
- # ```
536
- #
251
+ #
537
252
  # `JSHandle` instances can be passed as an argument to the [`method: Frame.evaluateHandle`]:
538
- #
539
253
  #
540
- # ```js
541
- # const aHandle = await frame.evaluateHandle(() => document.body);
542
- # const resultHandle = await frame.evaluateHandle(([body, suffix]) => body.innerHTML + suffix, [aHandle, 'hello']);
543
- # console.log(await resultHandle.jsonValue());
544
- # await resultHandle.dispose();
545
- # ```
546
- #
547
- # ```java
548
- # JSHandle aHandle = frame.evaluateHandle("() => document.body");
549
- # JSHandle resultHandle = frame.evaluateHandle("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(aHandle, "hello"));
550
- # System.out.println(resultHandle.jsonValue());
551
- # resultHandle.dispose();
552
- # ```
553
- #
554
- # ```python async
555
- # a_handle = await page.evaluate_handle("document.body")
556
- # result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
557
- # print(await result_handle.json_value())
558
- # await result_handle.dispose()
559
- # ```
560
- #
561
254
  # ```python sync
562
255
  # a_handle = page.evaluate_handle("document.body")
563
256
  # result_handle = page.evaluate_handle("body => body.innerHTML", a_handle)
564
257
  # print(result_handle.json_value())
565
258
  # result_handle.dispose()
566
259
  # ```
567
- #
568
- # ```csharp
569
- # var handle = await frame.EvaluateHandleAsync("() => document.body");
570
- # var resultHandle = await frame.EvaluateHandleAsync("([body, suffix]) => body.innerHTML + suffix", new object[] { handle, "hello" });
571
- # Console.WriteLine(await resultHandle.JsonValueAsync<string>());
572
- # await resultHandle.DisposeAsync();
573
- # ```
574
260
  def evaluate_handle(expression, arg: nil)
575
261
  wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg)))
576
262
  end
@@ -578,12 +264,12 @@ module Playwright
578
264
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, focuses the
579
265
  # element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
580
266
  # field.
581
- #
267
+ #
582
268
  # If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
583
269
  # However, if the element is inside the `<label>` element that has an associated
584
270
  # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
585
271
  # instead.
586
- #
272
+ #
587
273
  # To send fine-grained keyboard events, use [`method: Frame.type`].
588
274
  def fill(selector, value, noWaitAfter: nil, timeout: nil)
589
275
  wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
@@ -596,42 +282,17 @@ module Playwright
596
282
  end
597
283
 
598
284
  # Returns the `frame` or `iframe` element handle which corresponds to this frame.
599
- #
285
+ #
600
286
  # This is an inverse of [`method: ElementHandle.contentFrame`]. Note that returned handle actually belongs to the parent
601
287
  # frame.
602
- #
288
+ #
603
289
  # This method throws an error if the frame has been detached before `frameElement()` returns.
604
- #
605
290
  #
606
- # ```js
607
- # const frameElement = await frame.frameElement();
608
- # const contentFrame = await frameElement.contentFrame();
609
- # console.log(frame === contentFrame); // -> true
610
- # ```
611
- #
612
- # ```java
613
- # ElementHandle frameElement = frame.frameElement();
614
- # Frame contentFrame = frameElement.contentFrame();
615
- # System.out.println(frame == contentFrame); // -> true
616
- # ```
617
- #
618
- # ```python async
619
- # frame_element = await frame.frame_element()
620
- # content_frame = await frame_element.content_frame()
621
- # assert frame == content_frame
622
- # ```
623
- #
624
291
  # ```python sync
625
292
  # frame_element = frame.frame_element()
626
293
  # content_frame = frame_element.content_frame()
627
294
  # assert frame == content_frame
628
295
  # ```
629
- #
630
- # ```csharp
631
- # var frameElement = await frame.FrameElementAsync();
632
- # var contentFrame = await frameElement.ContentFrameAsync();
633
- # Console.WriteLine(frame == contentFrame); // -> True
634
- # ```
635
296
  def frame_element
636
297
  wrap_impl(@impl.frame_element)
637
298
  end
@@ -643,18 +304,18 @@ module Playwright
643
304
 
644
305
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
645
306
  # last redirect.
646
- #
307
+ #
647
308
  # `frame.goto` will throw an error if:
648
309
  # - there's an SSL error (e.g. in case of self-signed certificates).
649
310
  # - target URL is invalid.
650
311
  # - the `timeout` is exceeded during navigation.
651
312
  # - the remote server does not respond or is unreachable.
652
313
  # - the main resource failed to load.
653
- #
314
+ #
654
315
  # `frame.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404
655
316
  # "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
656
317
  # [`method: Response.status`].
657
- #
318
+ #
658
319
  # > NOTE: `frame.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
659
320
  # `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
660
321
  # > NOTE: Headless mode doesn't support navigation to a PDF document. See the
@@ -670,7 +331,7 @@ module Playwright
670
331
  # 1. Scroll the element into view if needed.
671
332
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
672
333
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
673
- #
334
+ #
674
335
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
675
336
  # zero timeout disables this.
676
337
  def hover(
@@ -731,9 +392,9 @@ module Playwright
731
392
  end
732
393
 
733
394
  # Returns frame's name attribute as specified in the tag.
734
- #
395
+ #
735
396
  # If the name is empty, returns the id attribute instead.
736
- #
397
+ #
737
398
  # > NOTE: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
738
399
  def name
739
400
  wrap_impl(@impl.name)
@@ -752,17 +413,17 @@ module Playwright
752
413
  # `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
753
414
  # value or a single character to generate the text for. A superset of the `key` values can be found
754
415
  # [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
755
- #
416
+ #
756
417
  # `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
757
418
  # `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
758
- #
419
+ #
759
420
  # Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
760
- #
421
+ #
761
422
  # Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
762
- #
423
+ #
763
424
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
764
425
  # texts.
765
- #
426
+ #
766
427
  # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
767
428
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
768
429
  def press(
@@ -775,7 +436,7 @@ module Playwright
775
436
  end
776
437
 
777
438
  # Returns the ElementHandle pointing to the frame element.
778
- #
439
+ #
779
440
  # The method finds an element matching the specified selector within the frame. See
780
441
  # [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
781
442
  def query_selector(selector)
@@ -783,7 +444,7 @@ module Playwright
783
444
  end
784
445
 
785
446
  # Returns the ElementHandles pointing to the frame elements.
786
- #
447
+ #
787
448
  # The method finds all elements matching the specified selector within the frame. See
788
449
  # [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns empty array.
789
450
  def query_selector_all(selector)
@@ -792,45 +453,15 @@ module Playwright
792
453
 
793
454
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, waits until
794
455
  # all specified options are present in the `<select>` element and selects these options.
795
- #
456
+ #
796
457
  # If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
797
458
  # `<label>` element that has an associated
798
459
  # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
799
- #
460
+ #
800
461
  # Returns the array of option values that have been successfully selected.
801
- #
462
+ #
802
463
  # Triggers a `change` and `input` event once all the provided options have been selected.
803
- #
804
- #
805
- # ```js
806
- # // single selection matching the value
807
- # frame.selectOption('select#colors', 'blue');
808
- #
809
- # // single selection matching both the value and the label
810
- # frame.selectOption('select#colors', { label: 'Blue' });
811
- #
812
- # // multiple selection
813
- # frame.selectOption('select#colors', 'red', 'green', 'blue');
814
- # ```
815
- #
816
- # ```java
817
- # // single selection matching the value
818
- # frame.selectOption("select#colors", "blue");
819
- # // single selection matching both the value and the label
820
- # frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
821
- # // multiple selection
822
- # frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
823
- # ```
824
- #
825
- # ```python async
826
- # # single selection matching the value
827
- # await frame.select_option("select#colors", "blue")
828
- # # single selection matching the label
829
- # await frame.select_option("select#colors", label="blue")
830
- # # multiple selection
831
- # await frame.select_option("select#colors", value=["red", "green", "blue"])
832
- # ```
833
- #
464
+ #
834
465
  # ```python sync
835
466
  # # single selection matching the value
836
467
  # frame.select_option("select#colors", "blue")
@@ -839,15 +470,6 @@ module Playwright
839
470
  # # multiple selection
840
471
  # frame.select_option("select#colors", value=["red", "green", "blue"])
841
472
  # ```
842
- #
843
- # ```csharp
844
- # // single selection matching the value
845
- # await frame.SelectOptionAsync("select#colors", new[] { "blue" });
846
- # // single selection matching both the value and the label
847
- # await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
848
- # // multiple selection
849
- # await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
850
- # ```
851
473
  def select_option(
852
474
  selector,
853
475
  element: nil,
@@ -866,7 +488,7 @@ module Playwright
866
488
 
867
489
  # This method expects `selector` to point to an
868
490
  # [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
869
- #
491
+ #
870
492
  # Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
871
493
  # are resolved relative to the the current working directory. For empty array, clears the selected files.
872
494
  def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
@@ -880,10 +502,10 @@ module Playwright
880
502
  # 1. Scroll the element into view if needed.
881
503
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
882
504
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
883
- #
505
+ #
884
506
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
885
507
  # zero timeout disables this.
886
- #
508
+ #
887
509
  # > NOTE: `frame.tap()` requires that the `hasTouch` option of the browser context be set to true.
888
510
  def tap_point(
889
511
  selector,
@@ -908,36 +530,13 @@ module Playwright
908
530
 
909
531
  # Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used to
910
532
  # send fine-grained keyboard events. To fill values in form fields, use [`method: Frame.fill`].
911
- #
533
+ #
912
534
  # To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
913
- #
914
535
  #
915
- # ```js
916
- # await frame.type('#mytextarea', 'Hello'); // Types instantly
917
- # await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
918
- # ```
919
- #
920
- # ```java
921
- # // Types instantly
922
- # frame.type("#mytextarea", "Hello");
923
- # // Types slower, like a user
924
- # frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
925
- # ```
926
- #
927
- # ```python async
928
- # await frame.type("#mytextarea", "hello") # types instantly
929
- # await frame.type("#mytextarea", "world", delay=100) # types slower, like a user
930
- # ```
931
- #
932
536
  # ```python sync
933
537
  # frame.type("#mytextarea", "hello") # types instantly
934
538
  # frame.type("#mytextarea", "world", delay=100) # types slower, like a user
935
539
  # ```
936
- #
937
- # ```csharp
938
- # await frame.TypeAsync("#mytextarea", "hello"); // types instantly
939
- # await frame.TypeAsync("#mytextarea", "world", delay: 100); // types slower, like a user
940
- # ```
941
540
  def type(
942
541
  selector,
943
542
  text,
@@ -957,7 +556,7 @@ module Playwright
957
556
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
958
557
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
959
558
  # 1. Ensure that the element is now unchecked. If not, this method throws.
960
- #
559
+ #
961
560
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
962
561
  # zero timeout disables this.
963
562
  def uncheck(
@@ -976,61 +575,12 @@ module Playwright
976
575
  end
977
576
 
978
577
  # Returns when the `expression` returns a truthy value, returns that value.
979
- #
578
+ #
980
579
  # The [`method: Frame.waitForFunction`] can be used to observe viewport size change:
981
- #
982
- #
983
- # ```js
984
- # const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
985
- #
986
- # (async () => {
987
- # const browser = await firefox.launch();
988
- # const page = await browser.newPage();
989
- # const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
990
- # page.setViewportSize({width: 50, height: 50});
991
- # await watchDog;
992
- # await browser.close();
993
- # })();
994
- # ```
995
- #
996
- # ```java
997
- # import com.microsoft.playwright.*;
998
- #
999
- # public class Example {
1000
- # public static void main(String[] args) {
1001
- # try (Playwright playwright = Playwright.create()) {
1002
- # BrowserType firefox = playwright.firefox();
1003
- # Browser browser = firefox.launch();
1004
- # Page page = browser.newPage();
1005
- # page.setViewportSize(50, 50);
1006
- # page.mainFrame().waitForFunction("window.innerWidth < 100");
1007
- # browser.close();
1008
- # }
1009
- # }
1010
- # }
1011
- # ```
1012
- #
1013
- # ```python async
1014
- # import asyncio
1015
- # from playwright.async_api import async_playwright
1016
- #
1017
- # async def run(playwright):
1018
- # webkit = playwright.webkit
1019
- # browser = await webkit.launch()
1020
- # page = await browser.new_page()
1021
- # await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1022
- # await page.main_frame.wait_for_function("() => window.x > 0")
1023
- # await browser.close()
1024
- #
1025
- # async def main():
1026
- # async with async_playwright() as playwright:
1027
- # await run(playwright)
1028
- # asyncio.run(main())
1029
- # ```
1030
- #
580
+ #
1031
581
  # ```python sync
1032
582
  # from playwright.sync_api import sync_playwright
1033
- #
583
+ #
1034
584
  # def run(playwright):
1035
585
  # webkit = playwright.webkit
1036
586
  # browser = webkit.launch()
@@ -1038,89 +588,30 @@ module Playwright
1038
588
  # page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1039
589
  # page.main_frame.wait_for_function("() => window.x > 0")
1040
590
  # browser.close()
1041
- #
591
+ #
1042
592
  # with sync_playwright() as playwright:
1043
593
  # run(playwright)
1044
594
  # ```
1045
- #
1046
- # ```csharp
1047
- # using Microsoft.Playwright;
1048
- # using System.Threading.Tasks;
1049
- #
1050
- # class FrameExamples
1051
- # {
1052
- # public static async Task Main()
1053
- # {
1054
- # using var playwright = await Playwright.CreateAsync();
1055
- # await using var browser = await playwright.Firefox.LaunchAsync();
1056
- # var page = await browser.NewPageAsync();
1057
- # await page.SetViewportSizeAsync(50, 50);
1058
- # await page.MainFrame.WaitForFunctionAsync("window.innerWidth < 100");
1059
- # }
1060
- # }
1061
- # ```
1062
- #
595
+ #
1063
596
  # To pass an argument to the predicate of `frame.waitForFunction` function:
1064
- #
1065
597
  #
1066
- # ```js
1067
- # const selector = '.foo';
1068
- # await frame.waitForFunction(selector => !!document.querySelector(selector), selector);
1069
- # ```
1070
- #
1071
- # ```java
1072
- # String selector = ".foo";
1073
- # frame.waitForFunction("selector => !!document.querySelector(selector)", selector);
1074
- # ```
1075
- #
1076
- # ```python async
1077
- # selector = ".foo"
1078
- # await frame.wait_for_function("selector => !!document.querySelector(selector)", selector)
1079
- # ```
1080
- #
1081
598
  # ```python sync
1082
599
  # selector = ".foo"
1083
600
  # frame.wait_for_function("selector => !!document.querySelector(selector)", selector)
1084
601
  # ```
1085
- #
1086
- # ```csharp
1087
- # var selector = ".foo";
1088
- # await page.MainFrame.WaitForFunctionAsync("selector => !!document.querySelector(selector)", selector);
1089
- # ```
1090
602
  def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
1091
603
  wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
1092
604
  end
1093
605
 
1094
606
  # Waits for the required load state to be reached.
1095
- #
607
+ #
1096
608
  # This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed
1097
609
  # when this method is called. If current document has already reached the required state, resolves immediately.
1098
- #
1099
610
  #
1100
- # ```js
1101
- # await frame.click('button'); // Click triggers navigation.
1102
- # await frame.waitForLoadState(); // Waits for 'load' state by default.
1103
- # ```
1104
- #
1105
- # ```java
1106
- # frame.click("button"); // Click triggers navigation.
1107
- # frame.waitForLoadState(); // Waits for "load" state by default.
1108
- # ```
1109
- #
1110
- # ```python async
1111
- # await frame.click("button") # click triggers navigation.
1112
- # await frame.wait_for_load_state() # the promise resolves after "load" event.
1113
- # ```
1114
- #
1115
611
  # ```python sync
1116
612
  # frame.click("button") # click triggers navigation.
1117
613
  # frame.wait_for_load_state() # the promise resolves after "load" event.
1118
614
  # ```
1119
- #
1120
- # ```csharp
1121
- # await frame.ClickAsync("button");
1122
- # await frame.WaitForLoadStateAsync(); // Defaults to LoadState.Load
1123
- # ```
1124
615
  def wait_for_load_state(state: nil, timeout: nil)
1125
616
  wrap_impl(@impl.wait_for_load_state(state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
1126
617
  end
@@ -1128,46 +619,16 @@ module Playwright
1128
619
  # Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
1129
620
  # will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
1130
621
  # History API usage, the navigation will resolve with `null`.
1131
- #
622
+ #
1132
623
  # This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause
1133
624
  # the frame to navigate. Consider this example:
1134
- #
1135
625
  #
1136
- # ```js
1137
- # const [response] = await Promise.all([
1138
- # frame.waitForNavigation(), // The promise resolves after navigation has finished
1139
- # frame.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
1140
- # ]);
1141
- # ```
1142
- #
1143
- # ```java
1144
- # // The method returns after navigation has finished
1145
- # Response response = frame.waitForNavigation(() -> {
1146
- # // Clicking the link will indirectly cause a navigation
1147
- # frame.click("a.delayed-navigation");
1148
- # });
1149
- # ```
1150
- #
1151
- # ```python async
1152
- # async with frame.expect_navigation():
1153
- # await frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1154
- # # Resolves after navigation has finished
1155
- # ```
1156
- #
1157
626
  # ```python sync
1158
627
  # with frame.expect_navigation():
1159
628
  # frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1160
629
  # # Resolves after navigation has finished
1161
630
  # ```
1162
- #
1163
- # ```csharp
1164
- # await Task.WhenAll(
1165
- # frame.WaitForNavigationAsync(),
1166
- # // clicking the link will indirectly cause a navigation
1167
- # frame.ClickAsync("a.delayed-navigation"));
1168
- # // Resolves after navigation has finished
1169
- # ```
1170
- #
631
+ #
1171
632
  # > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
1172
633
  # considered a navigation.
1173
634
  def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
@@ -1176,72 +637,16 @@ module Playwright
1176
637
 
1177
638
  # Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
1178
639
  # `detached`.
1179
- #
640
+ #
1180
641
  # Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
1181
642
  # the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
1182
643
  # selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
1183
- #
644
+ #
1184
645
  # This method works across navigations:
1185
- #
1186
- #
1187
- # ```js
1188
- # const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
1189
- #
1190
- # (async () => {
1191
- # const browser = await chromium.launch();
1192
- # const page = await browser.newPage();
1193
- # for (let currentURL of ['https://google.com', 'https://bbc.com']) {
1194
- # await page.goto(currentURL);
1195
- # const element = await page.mainFrame().waitForSelector('img');
1196
- # console.log('Loaded image: ' + await element.getAttribute('src'));
1197
- # }
1198
- # await browser.close();
1199
- # })();
1200
- # ```
1201
- #
1202
- # ```java
1203
- # import com.microsoft.playwright.*;
1204
- #
1205
- # public class Example {
1206
- # public static void main(String[] args) {
1207
- # try (Playwright playwright = Playwright.create()) {
1208
- # BrowserType chromium = playwright.chromium();
1209
- # Browser browser = chromium.launch();
1210
- # Page page = browser.newPage();
1211
- # for (String currentURL : Arrays.asList("https://google.com", "https://bbc.com")) {
1212
- # page.navigate(currentURL);
1213
- # ElementHandle element = page.mainFrame().waitForSelector("img");
1214
- # System.out.println("Loaded image: " + element.getAttribute("src"));
1215
- # }
1216
- # browser.close();
1217
- # }
1218
- # }
1219
- # }
1220
- # ```
1221
- #
1222
- # ```python async
1223
- # import asyncio
1224
- # from playwright.async_api import async_playwright
1225
- #
1226
- # async def run(playwright):
1227
- # chromium = playwright.chromium
1228
- # browser = await chromium.launch()
1229
- # page = await browser.new_page()
1230
- # for current_url in ["https://google.com", "https://bbc.com"]:
1231
- # await page.goto(current_url, wait_until="domcontentloaded")
1232
- # element = await page.main_frame.wait_for_selector("img")
1233
- # print("Loaded image: " + str(await element.get_attribute("src")))
1234
- # await browser.close()
1235
- #
1236
- # async def main():
1237
- # async with async_playwright() as playwright:
1238
- # await run(playwright)
1239
- # asyncio.run(main())
1240
- # ```
1241
- #
646
+ #
1242
647
  # ```python sync
1243
648
  # from playwright.sync_api import sync_playwright
1244
- #
649
+ #
1245
650
  # def run(playwright):
1246
651
  # chromium = playwright.chromium
1247
652
  # browser = chromium.launch()
@@ -1251,39 +656,16 @@ module Playwright
1251
656
  # element = page.main_frame.wait_for_selector("img")
1252
657
  # print("Loaded image: " + str(element.get_attribute("src")))
1253
658
  # browser.close()
1254
- #
659
+ #
1255
660
  # with sync_playwright() as playwright:
1256
661
  # run(playwright)
1257
662
  # ```
1258
- #
1259
- # ```csharp
1260
- # using Microsoft.Playwright;
1261
- # using System;
1262
- # using System.Threading.Tasks;
1263
- #
1264
- # class FrameExamples
1265
- # {
1266
- # public static async Task Main()
1267
- # {
1268
- # using var playwright = await Playwright.CreateAsync();
1269
- # await using var browser = await playwright.Chromium.LaunchAsync();
1270
- # var page = await browser.NewPageAsync();
1271
- #
1272
- # foreach (var currentUrl in new[] { "https://www.google.com", "https://bbc.com" })
1273
- # {
1274
- # await page.GotoAsync(currentUrl);
1275
- # element = await page.MainFrame.WaitForSelectorAsync("img");
1276
- # Console.WriteLine($"Loaded image: {await element.GetAttributeAsync("src")}");
1277
- # }
1278
- # }
1279
- # }
1280
- # ```
1281
663
  def wait_for_selector(selector, state: nil, timeout: nil)
1282
664
  wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
1283
665
  end
1284
666
 
1285
667
  # Waits for the given `timeout` in milliseconds.
1286
- #
668
+ #
1287
669
  # Note that `frame.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to
1288
670
  # be flaky. Use signals such as network events, selectors becoming visible and others instead.
1289
671
  def wait_for_timeout(timeout)
@@ -1291,32 +673,11 @@ module Playwright
1291
673
  end
1292
674
 
1293
675
  # Waits for the frame to navigate to the given URL.
1294
- #
1295
676
  #
1296
- # ```js
1297
- # await frame.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation
1298
- # await frame.waitForURL('**/target.html');
1299
- # ```
1300
- #
1301
- # ```java
1302
- # frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
1303
- # frame.waitForURL("**/target.html");
1304
- # ```
1305
- #
1306
- # ```python async
1307
- # await frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1308
- # await frame.wait_for_url("**/target.html")
1309
- # ```
1310
- #
1311
677
  # ```python sync
1312
678
  # frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1313
679
  # frame.wait_for_url("**/target.html")
1314
680
  # ```
1315
- #
1316
- # ```csharp
1317
- # await frame.ClickAsync("a.delayed-navigation"); // clicking the link will indirectly cause a navigation
1318
- # await frame.WaitForURLAsync("**/target.html");
1319
- # ```
1320
681
  def wait_for_url(url, timeout: nil, waitUntil: nil)
1321
682
  wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
1322
683
  end
@@ -1328,20 +689,20 @@ module Playwright
1328
689
 
1329
690
  # -- inherited from EventEmitter --
1330
691
  # @nodoc
1331
- def off(event, callback)
1332
- event_emitter_proxy.off(event, callback)
692
+ def on(event, callback)
693
+ event_emitter_proxy.on(event, callback)
1333
694
  end
1334
695
 
1335
696
  # -- inherited from EventEmitter --
1336
697
  # @nodoc
1337
- def once(event, callback)
1338
- event_emitter_proxy.once(event, callback)
698
+ def off(event, callback)
699
+ event_emitter_proxy.off(event, callback)
1339
700
  end
1340
701
 
1341
702
  # -- inherited from EventEmitter --
1342
703
  # @nodoc
1343
- def on(event, callback)
1344
- event_emitter_proxy.on(event, callback)
704
+ def once(event, callback)
705
+ event_emitter_proxy.once(event, callback)
1345
706
  end
1346
707
 
1347
708
  private def event_emitter_proxy