playwright-ruby-client 0.8.0 → 1.14.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +52 -1
  3. data/documentation/docs/api/browser.md +8 -2
  4. data/documentation/docs/api/browser_context.md +28 -0
  5. data/documentation/docs/api/browser_type.md +1 -0
  6. data/documentation/docs/api/download.md +97 -0
  7. data/documentation/docs/api/element_handle.md +28 -3
  8. data/documentation/docs/api/experimental/android_device.md +1 -0
  9. data/documentation/docs/api/frame.md +78 -18
  10. data/documentation/docs/api/keyboard.md +11 -20
  11. data/documentation/docs/api/locator.md +650 -0
  12. data/documentation/docs/api/page.md +124 -20
  13. data/documentation/docs/api/touchscreen.md +8 -0
  14. data/documentation/docs/api/worker.md +37 -0
  15. data/documentation/docs/article/guides/inspector.md +31 -0
  16. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +91 -0
  17. data/documentation/docs/article/guides/semi_automation.md +5 -1
  18. data/documentation/docs/include/api_coverage.md +72 -15
  19. data/lib/playwright.rb +0 -1
  20. data/lib/playwright/accessibility_impl.rb +50 -0
  21. data/lib/playwright/channel_owners/artifact.rb +4 -0
  22. data/lib/playwright/channel_owners/browser_context.rb +77 -3
  23. data/lib/playwright/channel_owners/frame.rb +101 -35
  24. data/lib/playwright/channel_owners/page.rb +157 -56
  25. data/lib/playwright/channel_owners/worker.rb +23 -0
  26. data/lib/playwright/{download.rb → download_impl.rb} +5 -1
  27. data/lib/playwright/javascript/expression.rb +5 -4
  28. data/lib/playwright/locator_impl.rb +314 -0
  29. data/lib/playwright/route_handler_entry.rb +3 -2
  30. data/lib/playwright/timeout_settings.rb +4 -4
  31. data/lib/playwright/touchscreen_impl.rb +7 -0
  32. data/lib/playwright/tracing_impl.rb +9 -8
  33. data/lib/playwright/url_matcher.rb +12 -2
  34. data/lib/playwright/version.rb +2 -2
  35. data/lib/playwright_api/accessibility.rb +1 -1
  36. data/lib/playwright_api/android.rb +6 -6
  37. data/lib/playwright_api/android_device.rb +8 -7
  38. data/lib/playwright_api/browser.rb +16 -10
  39. data/lib/playwright_api/browser_context.rb +16 -11
  40. data/lib/playwright_api/browser_type.rb +8 -7
  41. data/lib/playwright_api/cdp_session.rb +6 -6
  42. data/lib/playwright_api/console_message.rb +6 -6
  43. data/lib/playwright_api/dialog.rb +6 -6
  44. data/lib/playwright_api/download.rb +70 -0
  45. data/lib/playwright_api/element_handle.rb +34 -20
  46. data/lib/playwright_api/frame.rb +94 -52
  47. data/lib/playwright_api/js_handle.rb +6 -6
  48. data/lib/playwright_api/locator.rb +509 -0
  49. data/lib/playwright_api/page.rb +101 -57
  50. data/lib/playwright_api/playwright.rb +6 -6
  51. data/lib/playwright_api/request.rb +6 -6
  52. data/lib/playwright_api/response.rb +6 -6
  53. data/lib/playwright_api/route.rb +6 -11
  54. data/lib/playwright_api/selectors.rb +6 -6
  55. data/lib/playwright_api/touchscreen.rb +1 -1
  56. data/lib/playwright_api/web_socket.rb +6 -6
  57. data/lib/playwright_api/worker.rb +16 -6
  58. metadata +14 -6
@@ -7,19 +7,8 @@ module Playwright
7
7
  # method.
8
8
  #
9
9
  # ```python sync
10
- # from playwright.sync_api import sync_playwright
11
- #
12
- # def run(playwright):
13
- # chromium = playwright.chromium
14
- # browser = chromium.launch()
15
- # page = browser.new_page()
16
- # page.goto("https://example.com")
17
- # href_element = page.query_selector("a")
18
- # href_element.click()
19
- # # ...
20
- #
21
- # with sync_playwright() as playwright:
22
- # run(playwright)
10
+ # href_element = page.query_selector("a")
11
+ # href_element.click()
23
12
  # ```
24
13
  #
25
14
  # ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
@@ -27,6 +16,31 @@ module Playwright
27
16
  #
28
17
  # ElementHandle instances can be used as an argument in [`method: Page.evalOnSelector`] and [`method: Page.evaluate`]
29
18
  # methods.
19
+ #
20
+ # > NOTE: In most cases, you would want to use the `Locator` object instead. You should only use `ElementHandle` if you
21
+ # want to retain a handle to a particular DOM Node that you intend to pass into [`method: Page.evaluate`] as an argument.
22
+ #
23
+ # The difference between the `Locator` and ElementHandle is that the ElementHandle points to a particular element, while
24
+ # `Locator` captures the logic of how to retrieve an element.
25
+ #
26
+ # In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
27
+ # React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
28
+ # unexpected behaviors.
29
+ #
30
+ # ```python sync
31
+ # handle = page.query_selector("text=Submit")
32
+ # handle.hover()
33
+ # handle.click()
34
+ # ```
35
+ #
36
+ # With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
37
+ # in the snippet below, underlying DOM element is going to be located twice.
38
+ #
39
+ # ```python sync
40
+ # locator = page.locator("text=Submit")
41
+ # locator.hover()
42
+ # locator.click()
43
+ # ```
30
44
  class ElementHandle < JSHandle
31
45
 
32
46
  # This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
@@ -254,7 +268,7 @@ module Playwright
254
268
  wrap_impl(@impl.inner_text)
255
269
  end
256
270
 
257
- # Returns `input.value` for `<input>` or `<textarea>` element. Throws for non-input elements.
271
+ # Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
258
272
  def input_value(timeout: nil)
259
273
  wrap_impl(@impl.input_value(timeout: unwrap_impl(timeout)))
260
274
  end
@@ -515,12 +529,6 @@ module Playwright
515
529
  wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
516
530
  end
517
531
 
518
- # -- inherited from EventEmitter --
519
- # @nodoc
520
- def off(event, callback)
521
- event_emitter_proxy.off(event, callback)
522
- end
523
-
524
532
  # -- inherited from EventEmitter --
525
533
  # @nodoc
526
534
  def once(event, callback)
@@ -533,6 +541,12 @@ module Playwright
533
541
  event_emitter_proxy.on(event, callback)
534
542
  end
535
543
 
544
+ # -- inherited from EventEmitter --
545
+ # @nodoc
546
+ def off(event, callback)
547
+ event_emitter_proxy.off(event, callback)
548
+ end
549
+
536
550
  private def event_emitter_proxy
537
551
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
538
552
  end
@@ -65,9 +65,10 @@ module Playwright
65
65
  force: nil,
66
66
  noWaitAfter: nil,
67
67
  position: nil,
68
+ strict: nil,
68
69
  timeout: nil,
69
70
  trial: nil)
70
- wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
71
+ wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
71
72
  end
72
73
 
73
74
  def child_frames
@@ -93,9 +94,10 @@ module Playwright
93
94
  modifiers: nil,
94
95
  noWaitAfter: nil,
95
96
  position: nil,
97
+ strict: nil,
96
98
  timeout: nil,
97
99
  trial: nil)
98
- wrap_impl(@impl.click(unwrap_impl(selector), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
100
+ wrap_impl(@impl.click(unwrap_impl(selector), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
99
101
  end
100
102
 
101
103
  # Gets the full HTML contents of the frame, including the doctype.
@@ -124,9 +126,10 @@ module Playwright
124
126
  modifiers: nil,
125
127
  noWaitAfter: nil,
126
128
  position: nil,
129
+ strict: nil,
127
130
  timeout: nil,
128
131
  trial: nil)
129
- wrap_impl(@impl.dblclick(unwrap_impl(selector), button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
132
+ wrap_impl(@impl.dblclick(unwrap_impl(selector), button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
130
133
  end
131
134
 
132
135
  # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
@@ -156,8 +159,26 @@ module Playwright
156
159
  # data_transfer = frame.evaluate_handle("new DataTransfer()")
157
160
  # frame.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
158
161
  # ```
159
- def dispatch_event(selector, type, eventInit: nil, timeout: nil)
160
- wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
162
+ def dispatch_event(
163
+ selector,
164
+ type,
165
+ eventInit: nil,
166
+ strict: nil,
167
+ timeout: nil)
168
+ wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
169
+ end
170
+
171
+ def drag_and_drop(
172
+ source,
173
+ target,
174
+ force: nil,
175
+ noWaitAfter: nil,
176
+ sourcePosition: nil,
177
+ strict: nil,
178
+ targetPosition: nil,
179
+ timeout: nil,
180
+ trial: nil)
181
+ wrap_impl(@impl.drag_and_drop(unwrap_impl(source), unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), sourcePosition: unwrap_impl(sourcePosition), strict: unwrap_impl(strict), targetPosition: unwrap_impl(targetPosition), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
161
182
  end
162
183
 
163
184
  # Returns the return value of `expression`.
@@ -176,8 +197,8 @@ module Playwright
176
197
  # preload_href = frame.eval_on_selector("link[rel=preload]", "el => el.href")
177
198
  # html = frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
178
199
  # ```
179
- def eval_on_selector(selector, expression, arg: nil)
180
- wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
200
+ def eval_on_selector(selector, expression, arg: nil, strict: nil)
201
+ wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg), strict: unwrap_impl(strict)))
181
202
  end
182
203
 
183
204
  # Returns the return value of `expression`.
@@ -276,14 +297,15 @@ module Playwright
276
297
  value,
277
298
  force: nil,
278
299
  noWaitAfter: nil,
300
+ strict: nil,
279
301
  timeout: nil)
280
- wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
302
+ wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
281
303
  end
282
304
 
283
305
  # This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
284
306
  # waits until a matching element appears in the DOM.
285
- def focus(selector, timeout: nil)
286
- wrap_impl(@impl.focus(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
307
+ def focus(selector, strict: nil, timeout: nil)
308
+ wrap_impl(@impl.focus(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
287
309
  end
288
310
 
289
311
  # Returns the `frame` or `iframe` element handle which corresponds to this frame.
@@ -303,8 +325,8 @@ module Playwright
303
325
  end
304
326
 
305
327
  # Returns element attribute value.
306
- def get_attribute(selector, name, timeout: nil)
307
- wrap_impl(@impl.get_attribute(unwrap_impl(selector), unwrap_impl(name), timeout: unwrap_impl(timeout)))
328
+ def get_attribute(selector, name, strict: nil, timeout: nil)
329
+ wrap_impl(@impl.get_attribute(unwrap_impl(selector), unwrap_impl(name), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
308
330
  end
309
331
 
310
332
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
@@ -344,29 +366,30 @@ module Playwright
344
366
  force: nil,
345
367
  modifiers: nil,
346
368
  position: nil,
369
+ strict: nil,
347
370
  timeout: nil,
348
371
  trial: nil)
349
- wrap_impl(@impl.hover(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
372
+ wrap_impl(@impl.hover(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
350
373
  end
351
374
 
352
375
  # Returns `element.innerHTML`.
353
- def inner_html(selector, timeout: nil)
354
- wrap_impl(@impl.inner_html(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
376
+ def inner_html(selector, strict: nil, timeout: nil)
377
+ wrap_impl(@impl.inner_html(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
355
378
  end
356
379
 
357
380
  # Returns `element.innerText`.
358
- def inner_text(selector, timeout: nil)
359
- wrap_impl(@impl.inner_text(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
381
+ def inner_text(selector, strict: nil, timeout: nil)
382
+ wrap_impl(@impl.inner_text(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
360
383
  end
361
384
 
362
- # Returns `input.value` for the selected `<input>` or `<textarea>` element. Throws for non-input elements.
363
- def input_value(selector, timeout: nil)
364
- wrap_impl(@impl.input_value(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
385
+ # Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
386
+ def input_value(selector, strict: nil, timeout: nil)
387
+ wrap_impl(@impl.input_value(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
365
388
  end
366
389
 
367
390
  # Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
368
- def checked?(selector, timeout: nil)
369
- wrap_impl(@impl.checked?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
391
+ def checked?(selector, strict: nil, timeout: nil)
392
+ wrap_impl(@impl.checked?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
370
393
  end
371
394
 
372
395
  # Returns `true` if the frame has been detached, or `false` otherwise.
@@ -375,30 +398,39 @@ module Playwright
375
398
  end
376
399
 
377
400
  # Returns whether the element is disabled, the opposite of [enabled](./actionability.md#enabled).
378
- def disabled?(selector, timeout: nil)
379
- wrap_impl(@impl.disabled?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
401
+ def disabled?(selector, strict: nil, timeout: nil)
402
+ wrap_impl(@impl.disabled?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
380
403
  end
381
404
 
382
405
  # Returns whether the element is [editable](./actionability.md#editable).
383
- def editable?(selector, timeout: nil)
384
- wrap_impl(@impl.editable?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
406
+ def editable?(selector, strict: nil, timeout: nil)
407
+ wrap_impl(@impl.editable?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
385
408
  end
386
409
 
387
410
  # Returns whether the element is [enabled](./actionability.md#enabled).
388
- def enabled?(selector, timeout: nil)
389
- wrap_impl(@impl.enabled?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
411
+ def enabled?(selector, strict: nil, timeout: nil)
412
+ wrap_impl(@impl.enabled?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
390
413
  end
391
414
 
392
415
  # Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not
393
416
  # match any elements is considered hidden.
394
- def hidden?(selector, timeout: nil)
395
- wrap_impl(@impl.hidden?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
417
+ def hidden?(selector, strict: nil, timeout: nil)
418
+ wrap_impl(@impl.hidden?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
396
419
  end
397
420
 
398
421
  # Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is
399
422
  # considered not visible.
400
- def visible?(selector, timeout: nil)
401
- wrap_impl(@impl.visible?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
423
+ def visible?(selector, strict: nil, timeout: nil)
424
+ wrap_impl(@impl.visible?(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
425
+ end
426
+
427
+ # The method returns an element locator that can be used to perform actions in the frame. Locator is resolved to the
428
+ # element immediately before performing an action, so a series of actions on the same locator can in fact be performed on
429
+ # different DOM elements. That would happen if the DOM structure between those actions has changed.
430
+ #
431
+ # Note that locator always implies visibility, so it will always be locating visible elements.
432
+ def locator(selector)
433
+ wrap_impl(@impl.locator(unwrap_impl(selector)))
402
434
  end
403
435
 
404
436
  # Returns frame's name attribute as specified in the tag.
@@ -441,16 +473,17 @@ module Playwright
441
473
  key,
442
474
  delay: nil,
443
475
  noWaitAfter: nil,
476
+ strict: nil,
444
477
  timeout: nil)
445
- wrap_impl(@impl.press(unwrap_impl(selector), unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
478
+ wrap_impl(@impl.press(unwrap_impl(selector), unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
446
479
  end
447
480
 
448
481
  # Returns the ElementHandle pointing to the frame element.
449
482
  #
450
483
  # The method finds an element matching the specified selector within the frame. See
451
484
  # [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
452
- def query_selector(selector)
453
- wrap_impl(@impl.query_selector(unwrap_impl(selector)))
485
+ def query_selector(selector, strict: nil)
486
+ wrap_impl(@impl.query_selector(unwrap_impl(selector), strict: unwrap_impl(strict)))
454
487
  end
455
488
 
456
489
  # Returns the ElementHandles pointing to the frame elements.
@@ -488,8 +521,9 @@ module Playwright
488
521
  label: nil,
489
522
  force: nil,
490
523
  noWaitAfter: nil,
524
+ strict: nil,
491
525
  timeout: nil)
492
- wrap_impl(@impl.select_option(unwrap_impl(selector), element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
526
+ wrap_impl(@impl.select_option(unwrap_impl(selector), element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
493
527
  end
494
528
 
495
529
  def set_content(html, timeout: nil, waitUntil: nil)
@@ -502,8 +536,13 @@ module Playwright
502
536
  #
503
537
  # Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
504
538
  # are resolved relative to the the current working directory. For empty array, clears the selected files.
505
- def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
506
- wrap_impl(@impl.set_input_files(unwrap_impl(selector), unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
539
+ def set_input_files(
540
+ selector,
541
+ files,
542
+ noWaitAfter: nil,
543
+ strict: nil,
544
+ timeout: nil)
545
+ wrap_impl(@impl.set_input_files(unwrap_impl(selector), unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
507
546
  end
508
547
 
509
548
  # This method taps an element matching `selector` by performing the following steps:
@@ -524,14 +563,15 @@ module Playwright
524
563
  modifiers: nil,
525
564
  noWaitAfter: nil,
526
565
  position: nil,
566
+ strict: nil,
527
567
  timeout: nil,
528
568
  trial: nil)
529
- wrap_impl(@impl.tap_point(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
569
+ wrap_impl(@impl.tap_point(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
530
570
  end
531
571
 
532
572
  # Returns `element.textContent`.
533
- def text_content(selector, timeout: nil)
534
- wrap_impl(@impl.text_content(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
573
+ def text_content(selector, strict: nil, timeout: nil)
574
+ wrap_impl(@impl.text_content(unwrap_impl(selector), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
535
575
  end
536
576
 
537
577
  # Returns the page title.
@@ -553,8 +593,9 @@ module Playwright
553
593
  text,
554
594
  delay: nil,
555
595
  noWaitAfter: nil,
596
+ strict: nil,
556
597
  timeout: nil)
557
- wrap_impl(@impl.type(unwrap_impl(selector), unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
598
+ wrap_impl(@impl.type(unwrap_impl(selector), unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
558
599
  end
559
600
 
560
601
  # This method checks an element matching `selector` by performing the following steps:
@@ -575,9 +616,10 @@ module Playwright
575
616
  force: nil,
576
617
  noWaitAfter: nil,
577
618
  position: nil,
619
+ strict: nil,
578
620
  timeout: nil,
579
621
  trial: nil)
580
- wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
622
+ wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
581
623
  end
582
624
 
583
625
  # Returns frame's url.
@@ -671,8 +713,8 @@ module Playwright
671
713
  # with sync_playwright() as playwright:
672
714
  # run(playwright)
673
715
  # ```
674
- def wait_for_selector(selector, state: nil, timeout: nil)
675
- wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
716
+ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
717
+ wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
676
718
  end
677
719
 
678
720
  # Waits for the given `timeout` in milliseconds.
@@ -680,7 +722,7 @@ module Playwright
680
722
  # Note that `frame.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to
681
723
  # be flaky. Use signals such as network events, selectors becoming visible and others instead.
682
724
  def wait_for_timeout(timeout)
683
- raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
725
+ wrap_impl(@impl.wait_for_timeout(unwrap_impl(timeout)))
684
726
  end
685
727
 
686
728
  # Waits for the frame to navigate to the given URL.
@@ -698,12 +740,6 @@ module Playwright
698
740
  wrap_impl(@impl.detached=(unwrap_impl(req)))
699
741
  end
700
742
 
701
- # -- inherited from EventEmitter --
702
- # @nodoc
703
- def off(event, callback)
704
- event_emitter_proxy.off(event, callback)
705
- end
706
-
707
743
  # -- inherited from EventEmitter --
708
744
  # @nodoc
709
745
  def once(event, callback)
@@ -716,6 +752,12 @@ module Playwright
716
752
  event_emitter_proxy.on(event, callback)
717
753
  end
718
754
 
755
+ # -- inherited from EventEmitter --
756
+ # @nodoc
757
+ def off(event, callback)
758
+ event_emitter_proxy.off(event, callback)
759
+ end
760
+
719
761
  private def event_emitter_proxy
720
762
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
721
763
  end
@@ -88,12 +88,6 @@ module Playwright
88
88
  wrap_impl(@impl.to_s)
89
89
  end
90
90
 
91
- # -- inherited from EventEmitter --
92
- # @nodoc
93
- def off(event, callback)
94
- event_emitter_proxy.off(event, callback)
95
- end
96
-
97
91
  # -- inherited from EventEmitter --
98
92
  # @nodoc
99
93
  def once(event, callback)
@@ -106,6 +100,12 @@ module Playwright
106
100
  event_emitter_proxy.on(event, callback)
107
101
  end
108
102
 
103
+ # -- inherited from EventEmitter --
104
+ # @nodoc
105
+ def off(event, callback)
106
+ event_emitter_proxy.off(event, callback)
107
+ end
108
+
109
109
  private def event_emitter_proxy
110
110
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
111
111
  end
@@ -0,0 +1,509 @@
1
+ module Playwright
2
+ # Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
3
+ # given moment. Locator can be created with the [`method: Page.locator`] method.
4
+ #
5
+ # ```python sync
6
+ # locator = page.locator("text=Submit")
7
+ # locator.click()
8
+ # ```
9
+ #
10
+ # The difference between the Locator and `ElementHandle` is that the latter points to a particular element, while Locator
11
+ # captures the logic of how to retrieve that element.
12
+ #
13
+ # In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
14
+ # React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
15
+ # unexpected behaviors.
16
+ #
17
+ # ```python sync
18
+ # handle = page.query_selector("text=Submit")
19
+ # handle.hover()
20
+ # handle.click()
21
+ # ```
22
+ #
23
+ # With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
24
+ # in the snippet below, underlying DOM element is going to be located twice.
25
+ #
26
+ # ```python sync
27
+ # locator = page.locator("text=Submit")
28
+ # locator.hover()
29
+ # locator.click()
30
+ # ```
31
+ class Locator < PlaywrightApi
32
+
33
+ # Returns an array of `node.innerText` values for all matching nodes.
34
+ def all_inner_texts
35
+ wrap_impl(@impl.all_inner_texts)
36
+ end
37
+
38
+ # Returns an array of `node.textContent` values for all matching nodes.
39
+ def all_text_contents
40
+ wrap_impl(@impl.all_text_contents)
41
+ end
42
+
43
+ # This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
44
+ # calculated relative to the main frame viewport - which is usually the same as the browser window.
45
+ #
46
+ # Scrolling affects the returned bonding box, similarly to
47
+ # [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
48
+ # means `x` and/or `y` may be negative.
49
+ #
50
+ # Elements from child frames return the bounding box relative to the main frame, unlike the
51
+ # [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
52
+ #
53
+ # Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
54
+ # snippet should click the center of the element.
55
+ #
56
+ # ```python sync
57
+ # box = element.bounding_box()
58
+ # page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
59
+ # ```
60
+ def bounding_box(timeout: nil)
61
+ wrap_impl(@impl.bounding_box(timeout: unwrap_impl(timeout)))
62
+ end
63
+
64
+ # This method checks the element by performing the following steps:
65
+ # 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked,
66
+ # this method returns immediately.
67
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
68
+ # 1. Scroll the element into view if needed.
69
+ # 1. Use [`property: Page.mouse`] to click in the center of the element.
70
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
71
+ # 1. Ensure that the element is now checked. If not, this method throws.
72
+ #
73
+ # If the element is detached from the DOM at any moment during the action, this method throws.
74
+ #
75
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
76
+ # zero timeout disables this.
77
+ def check(
78
+ force: nil,
79
+ noWaitAfter: nil,
80
+ position: nil,
81
+ timeout: nil,
82
+ trial: nil)
83
+ wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
84
+ end
85
+
86
+ # This method clicks the element by performing the following steps:
87
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
88
+ # 1. Scroll the element into view if needed.
89
+ # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
90
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
91
+ #
92
+ # If the element is detached from the DOM at any moment during the action, this method throws.
93
+ #
94
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
95
+ # zero timeout disables this.
96
+ def click(
97
+ button: nil,
98
+ clickCount: nil,
99
+ delay: nil,
100
+ force: nil,
101
+ modifiers: nil,
102
+ noWaitAfter: nil,
103
+ position: nil,
104
+ timeout: nil,
105
+ trial: nil)
106
+ wrap_impl(@impl.click(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
107
+ end
108
+
109
+ # Returns the number of elements matching given selector.
110
+ def count
111
+ wrap_impl(@impl.count)
112
+ end
113
+
114
+ # This method double clicks the element by performing the following steps:
115
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
116
+ # 1. Scroll the element into view if needed.
117
+ # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
118
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
119
+ # first click of the `dblclick()` triggers a navigation event, this method will throw.
120
+ #
121
+ # If the element is detached from the DOM at any moment during the action, this method throws.
122
+ #
123
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
124
+ # zero timeout disables this.
125
+ #
126
+ # > NOTE: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
127
+ def dblclick(
128
+ button: nil,
129
+ delay: nil,
130
+ force: nil,
131
+ modifiers: nil,
132
+ noWaitAfter: nil,
133
+ position: nil,
134
+ timeout: nil,
135
+ trial: nil)
136
+ wrap_impl(@impl.dblclick(button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
137
+ end
138
+
139
+ # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
140
+ # `click` is dispatched. This is equivalent to calling
141
+ # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
142
+ #
143
+ # ```python sync
144
+ # element.dispatch_event("click")
145
+ # ```
146
+ #
147
+ # Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
148
+ # and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
149
+ #
150
+ # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
151
+ # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
152
+ # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
153
+ # - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
154
+ # - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
155
+ # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
156
+ # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
157
+ # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
158
+ #
159
+ # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
160
+ #
161
+ # ```python sync
162
+ # # note you can only create data_transfer in chromium and firefox
163
+ # data_transfer = page.evaluate_handle("new DataTransfer()")
164
+ # element.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
165
+ # ```
166
+ def dispatch_event(type, eventInit: nil, timeout: nil)
167
+ wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
168
+ end
169
+
170
+ # Resolves given locator to the first matching DOM element. If no elements matching the query are visible, waits for them
171
+ # up to a given timeout. If multiple elements match the selector, throws.
172
+ def element_handle(timeout: nil)
173
+ wrap_impl(@impl.element_handle(timeout: unwrap_impl(timeout)))
174
+ end
175
+
176
+ # Resolves given locator to all matching DOM elements.
177
+ def element_handles
178
+ wrap_impl(@impl.element_handles)
179
+ end
180
+
181
+ # Returns the return value of `expression`.
182
+ #
183
+ # This method passes this handle as the first argument to `expression`.
184
+ #
185
+ # If `expression` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its value.
186
+ #
187
+ # Examples:
188
+ #
189
+ # ```python sync
190
+ # tweets = page.locator(".tweet .retweets")
191
+ # assert tweets.evaluate("node => node.innerText") == "10 retweets"
192
+ # ```
193
+ def evaluate(expression, arg: nil, timeout: nil)
194
+ wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
195
+ end
196
+
197
+ # The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
198
+ # to `expression`. Returns the result of `expression` invocation.
199
+ #
200
+ # If `expression` returns a [Promise], then [`Locator.evaluateAll`] would wait for the promise to resolve and return its
201
+ # value.
202
+ #
203
+ # Examples:
204
+ #
205
+ # ```python sync
206
+ # elements = page.locator("div")
207
+ # div_counts = elements("(divs, min) => divs.length >= min", 10)
208
+ # ```
209
+ def evaluate_all(expression, arg: nil)
210
+ wrap_impl(@impl.evaluate_all(unwrap_impl(expression), arg: unwrap_impl(arg)))
211
+ end
212
+
213
+ # Returns the return value of `expression` as a `JSHandle`.
214
+ #
215
+ # This method passes this handle as the first argument to `expression`.
216
+ #
217
+ # The only difference between [`method: Locator.evaluate`] and [`method: Locator.evaluateHandle`] is that
218
+ # [`method: Locator.evaluateHandle`] returns `JSHandle`.
219
+ #
220
+ # If the function passed to the [`method: Locator.evaluateHandle`] returns a [Promise], then
221
+ # [`method: Locator.evaluateHandle`] would wait for the promise to resolve and return its value.
222
+ #
223
+ # See [`method: Page.evaluateHandle`] for more details.
224
+ def evaluate_handle(expression, arg: nil, timeout: nil)
225
+ wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg), timeout: unwrap_impl(timeout)))
226
+ end
227
+
228
+ # This method waits for [actionability](./actionability.md) checks, focuses the element, fills it and triggers an `input`
229
+ # event after filling. Note that you can pass an empty string to clear the input field.
230
+ #
231
+ # If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
232
+ # However, if the element is inside the `<label>` element that has an associated
233
+ # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
234
+ # instead.
235
+ #
236
+ # To send fine-grained keyboard events, use [`method: Locator.type`].
237
+ def fill(value, force: nil, noWaitAfter: nil, timeout: nil)
238
+ wrap_impl(@impl.fill(unwrap_impl(value), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
239
+ end
240
+
241
+ # Returns locator to the first matching element.
242
+ def first
243
+ wrap_impl(@impl.first)
244
+ end
245
+
246
+ # Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element.
247
+ def focus(timeout: nil)
248
+ wrap_impl(@impl.focus(timeout: unwrap_impl(timeout)))
249
+ end
250
+
251
+ # Returns element attribute value.
252
+ def get_attribute(name, timeout: nil)
253
+ wrap_impl(@impl.get_attribute(unwrap_impl(name), timeout: unwrap_impl(timeout)))
254
+ end
255
+
256
+ # This method hovers over the element by performing the following steps:
257
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
258
+ # 1. Scroll the element into view if needed.
259
+ # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
260
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
261
+ #
262
+ # If the element is detached from the DOM at any moment during the action, this method throws.
263
+ #
264
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
265
+ # zero timeout disables this.
266
+ def hover(
267
+ force: nil,
268
+ modifiers: nil,
269
+ position: nil,
270
+ timeout: nil,
271
+ trial: nil)
272
+ wrap_impl(@impl.hover(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
273
+ end
274
+
275
+ # Returns the `element.innerHTML`.
276
+ def inner_html(timeout: nil)
277
+ wrap_impl(@impl.inner_html(timeout: unwrap_impl(timeout)))
278
+ end
279
+
280
+ # Returns the `element.innerText`.
281
+ def inner_text(timeout: nil)
282
+ wrap_impl(@impl.inner_text(timeout: unwrap_impl(timeout)))
283
+ end
284
+
285
+ # Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
286
+ def input_value(timeout: nil)
287
+ wrap_impl(@impl.input_value(timeout: unwrap_impl(timeout)))
288
+ end
289
+
290
+ # Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
291
+ def checked?(timeout: nil)
292
+ wrap_impl(@impl.checked?(timeout: unwrap_impl(timeout)))
293
+ end
294
+
295
+ # Returns whether the element is disabled, the opposite of [enabled](./actionability.md#enabled).
296
+ def disabled?(timeout: nil)
297
+ wrap_impl(@impl.disabled?(timeout: unwrap_impl(timeout)))
298
+ end
299
+
300
+ # Returns whether the element is [editable](./actionability.md#editable).
301
+ def editable?(timeout: nil)
302
+ wrap_impl(@impl.editable?(timeout: unwrap_impl(timeout)))
303
+ end
304
+
305
+ # Returns whether the element is [enabled](./actionability.md#enabled).
306
+ def enabled?(timeout: nil)
307
+ wrap_impl(@impl.enabled?(timeout: unwrap_impl(timeout)))
308
+ end
309
+
310
+ # Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
311
+ def hidden?(timeout: nil)
312
+ wrap_impl(@impl.hidden?(timeout: unwrap_impl(timeout)))
313
+ end
314
+
315
+ # Returns whether the element is [visible](./actionability.md#visible).
316
+ def visible?(timeout: nil)
317
+ wrap_impl(@impl.visible?(timeout: unwrap_impl(timeout)))
318
+ end
319
+
320
+ # Returns locator to the last matching element.
321
+ def last
322
+ wrap_impl(@impl.last)
323
+ end
324
+
325
+ # The method finds an element matching the specified selector in the `Locator`'s subtree. See
326
+ # [Working with selectors](./selectors.md) for more details.
327
+ def locator(selector)
328
+ wrap_impl(@impl.locator(unwrap_impl(selector)))
329
+ end
330
+
331
+ # Returns locator to the n-th matching element.
332
+ def nth(index)
333
+ wrap_impl(@impl.nth(unwrap_impl(index)))
334
+ end
335
+
336
+ # Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
337
+ #
338
+ # `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
339
+ # value or a single character to generate the text for. A superset of the `key` values can be found
340
+ # [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
341
+ #
342
+ # `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
343
+ # `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
344
+ #
345
+ # Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
346
+ #
347
+ # Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
348
+ #
349
+ # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
350
+ # texts.
351
+ #
352
+ # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
353
+ # modifier, modifier is pressed and being held while the subsequent key is being pressed.
354
+ def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
355
+ wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
356
+ end
357
+
358
+ # Returns the buffer with the captured screenshot.
359
+ #
360
+ # This method waits for the [actionability](./actionability.md) checks, then scrolls element into view before taking a
361
+ # screenshot. If the element is detached from DOM, the method throws an error.
362
+ def screenshot(
363
+ omitBackground: nil,
364
+ path: nil,
365
+ quality: nil,
366
+ timeout: nil,
367
+ type: nil)
368
+ wrap_impl(@impl.screenshot(omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
369
+ end
370
+
371
+ # This method waits for [actionability](./actionability.md) checks, then tries to scroll element into view, unless it is
372
+ # completely visible as defined by
373
+ # [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
374
+ def scroll_into_view_if_needed(timeout: nil)
375
+ wrap_impl(@impl.scroll_into_view_if_needed(timeout: unwrap_impl(timeout)))
376
+ end
377
+
378
+ # This method waits for [actionability](./actionability.md) checks, waits until all specified options are present in the
379
+ # `<select>` element and selects these options.
380
+ #
381
+ # If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
382
+ # `<label>` element that has an associated
383
+ # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
384
+ #
385
+ # Returns the array of option values that have been successfully selected.
386
+ #
387
+ # Triggers a `change` and `input` event once all the provided options have been selected.
388
+ #
389
+ # ```python sync
390
+ # # single selection matching the value
391
+ # element.select_option("blue")
392
+ # # single selection matching both the label
393
+ # element.select_option(label="blue")
394
+ # # multiple selection
395
+ # element.select_option(value=["red", "green", "blue"])
396
+ # ```
397
+ #
398
+ # ```python sync
399
+ # # single selection matching the value
400
+ # element.select_option("blue")
401
+ # # single selection matching both the value and the label
402
+ # element.select_option(label="blue")
403
+ # # multiple selection
404
+ # element.select_option("red", "green", "blue")
405
+ # # multiple selection for blue, red and second option
406
+ # element.select_option(value="blue", { index: 2 }, "red")
407
+ # ```
408
+ def select_option(
409
+ element: nil,
410
+ index: nil,
411
+ value: nil,
412
+ label: nil,
413
+ force: nil,
414
+ noWaitAfter: nil,
415
+ timeout: nil)
416
+ wrap_impl(@impl.select_option(element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
417
+ end
418
+
419
+ # This method waits for [actionability](./actionability.md) checks, then focuses the element and selects all its text
420
+ # content.
421
+ def select_text(force: nil, timeout: nil)
422
+ wrap_impl(@impl.select_text(force: unwrap_impl(force), timeout: unwrap_impl(timeout)))
423
+ end
424
+
425
+ # This method expects `element` to point to an
426
+ # [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
427
+ #
428
+ # Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
429
+ # are resolved relative to the the current working directory. For empty array, clears the selected files.
430
+ def set_input_files(files, noWaitAfter: nil, timeout: nil)
431
+ wrap_impl(@impl.set_input_files(unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
432
+ end
433
+ alias_method :input_files=, :set_input_files
434
+
435
+ # This method taps the element by performing the following steps:
436
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
437
+ # 1. Scroll the element into view if needed.
438
+ # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
439
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
440
+ #
441
+ # If the element is detached from the DOM at any moment during the action, this method throws.
442
+ #
443
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
444
+ # zero timeout disables this.
445
+ #
446
+ # > NOTE: `element.tap()` requires that the `hasTouch` option of the browser context be set to true.
447
+ def tap_point(
448
+ force: nil,
449
+ modifiers: nil,
450
+ noWaitAfter: nil,
451
+ position: nil,
452
+ timeout: nil,
453
+ trial: nil)
454
+ wrap_impl(@impl.tap_point(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
455
+ end
456
+
457
+ # Returns the `node.textContent`.
458
+ def text_content(timeout: nil)
459
+ wrap_impl(@impl.text_content(timeout: unwrap_impl(timeout)))
460
+ end
461
+
462
+ # Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
463
+ #
464
+ # To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
465
+ #
466
+ # ```python sync
467
+ # element.type("hello") # types instantly
468
+ # element.type("world", delay=100) # types slower, like a user
469
+ # ```
470
+ #
471
+ # An example of typing into a text field and then submitting the form:
472
+ #
473
+ # ```python sync
474
+ # element = page.locator("input")
475
+ # element.type("some text")
476
+ # element.press("Enter")
477
+ # ```
478
+ def type(text, delay: nil, noWaitAfter: nil, timeout: nil)
479
+ wrap_impl(@impl.type(unwrap_impl(text), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
480
+ end
481
+
482
+ # This method checks the element by performing the following steps:
483
+ # 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
484
+ # unchecked, this method returns immediately.
485
+ # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
486
+ # 1. Scroll the element into view if needed.
487
+ # 1. Use [`property: Page.mouse`] to click in the center of the element.
488
+ # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
489
+ # 1. Ensure that the element is now unchecked. If not, this method throws.
490
+ #
491
+ # If the element is detached from the DOM at any moment during the action, this method throws.
492
+ #
493
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
494
+ # zero timeout disables this.
495
+ def uncheck(
496
+ force: nil,
497
+ noWaitAfter: nil,
498
+ position: nil,
499
+ timeout: nil,
500
+ trial: nil)
501
+ wrap_impl(@impl.uncheck(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
502
+ end
503
+
504
+ # @nodoc
505
+ def to_s
506
+ wrap_impl(@impl.to_s)
507
+ end
508
+ end
509
+ end