playwright-ruby-client 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/docs/api/download.md +97 -0
- data/documentation/docs/api/element_handle.md +27 -2
- data/documentation/docs/api/frame.md +50 -17
- data/documentation/docs/api/locator.md +650 -0
- data/documentation/docs/api/page.md +68 -18
- data/documentation/docs/article/guides/inspector.md +31 -0
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
- data/documentation/docs/article/guides/semi_automation.md +1 -1
- data/documentation/docs/include/api_coverage.md +57 -1
- data/lib/playwright.rb +0 -1
- data/lib/playwright/channel_owners/browser_context.rb +25 -0
- data/lib/playwright/channel_owners/frame.rb +70 -33
- data/lib/playwright/channel_owners/page.rb +102 -40
- data/lib/playwright/{download.rb → download_impl.rb} +1 -1
- data/lib/playwright/javascript/expression.rb +5 -4
- data/lib/playwright/locator_impl.rb +314 -0
- data/lib/playwright/timeout_settings.rb +4 -4
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/android.rb +6 -6
- data/lib/playwright_api/android_device.rb +6 -6
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +16 -11
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/download.rb +70 -0
- data/lib/playwright_api/element_handle.rb +33 -19
- data/lib/playwright_api/frame.rb +81 -51
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +509 -0
- data/lib/playwright_api/page.rb +84 -52
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +6 -6
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c0e5286a6e8faaa590ce17ed083f4e6f93c54fb6899571c5edc2a99c4148b15
|
4
|
+
data.tar.gz: bccd47264ec992c5c901c94faf28ec346a606d75e4636ae80828e5d64a685bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c34792ec1bb838c99b5a540833c7e02c718147738d2b6129eb9ba63f53e6d6d1460e5abc62f9e94fecec2bc9dd07321c9badc1c4e4173ae0548151ebcbc38e12
|
7
|
+
data.tar.gz: 12b99906a534b8ec3a5eef041824ec4d0357fe70e3a1c696dc4f11a95c1b54edbe8c7a5d67694c7b9dc846bd34fa6e18fbb3d84f241aa345a1d89c8af4ac4a39
|
@@ -0,0 +1,97 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Download
|
6
|
+
|
7
|
+
[Download](./download) objects are dispatched by page via the [`event: Page.download`] event.
|
8
|
+
|
9
|
+
All the downloaded files belonging to the browser context are deleted when the browser context is closed.
|
10
|
+
|
11
|
+
Download event is emitted once the download starts. Download path becomes available once download completes:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
download = page.expect_download do
|
15
|
+
page.click('a')
|
16
|
+
end
|
17
|
+
|
18
|
+
# wait for download to complete
|
19
|
+
path = download.path
|
20
|
+
```
|
21
|
+
|
22
|
+
> NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
|
23
|
+
downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
|
24
|
+
performed and user has no access to the downloaded files.
|
25
|
+
|
26
|
+
## cancel
|
27
|
+
|
28
|
+
```
|
29
|
+
def cancel
|
30
|
+
```
|
31
|
+
|
32
|
+
Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations,
|
33
|
+
`download.failure()` would resolve to `'canceled'`.
|
34
|
+
|
35
|
+
## delete
|
36
|
+
|
37
|
+
```
|
38
|
+
def delete
|
39
|
+
```
|
40
|
+
|
41
|
+
Deletes the downloaded file. Will wait for the download to finish if necessary.
|
42
|
+
|
43
|
+
## failure
|
44
|
+
|
45
|
+
```
|
46
|
+
def failure
|
47
|
+
```
|
48
|
+
|
49
|
+
Returns download error if any. Will wait for the download to finish if necessary.
|
50
|
+
|
51
|
+
## page
|
52
|
+
|
53
|
+
```
|
54
|
+
def page
|
55
|
+
```
|
56
|
+
|
57
|
+
Get the page that the download belongs to.
|
58
|
+
|
59
|
+
## path
|
60
|
+
|
61
|
+
```
|
62
|
+
def path
|
63
|
+
```
|
64
|
+
|
65
|
+
Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
|
66
|
+
necessary. The method throws when connected remotely.
|
67
|
+
|
68
|
+
Note that the download's file name is a random GUID, use [Download#suggested_filename](./download#suggested_filename) to get suggested file
|
69
|
+
name.
|
70
|
+
|
71
|
+
## save_as
|
72
|
+
|
73
|
+
```
|
74
|
+
def save_as(path)
|
75
|
+
```
|
76
|
+
|
77
|
+
Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will
|
78
|
+
wait for the download to finish if necessary.
|
79
|
+
|
80
|
+
## suggested_filename
|
81
|
+
|
82
|
+
```
|
83
|
+
def suggested_filename
|
84
|
+
```
|
85
|
+
|
86
|
+
Returns suggested filename for this download. It is typically computed by the browser from the
|
87
|
+
[`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header
|
88
|
+
or the `download` attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources). Different
|
89
|
+
browsers can use different logic for computing it.
|
90
|
+
|
91
|
+
## url
|
92
|
+
|
93
|
+
```
|
94
|
+
def url
|
95
|
+
```
|
96
|
+
|
97
|
+
Returns downloaded url.
|
@@ -10,10 +10,8 @@ ElementHandle represents an in-page DOM element. ElementHandles can be created w
|
|
10
10
|
method.
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
page.goto("https://example.com")
|
14
13
|
href_element = page.query_selector("a")
|
15
14
|
href_element.click
|
16
|
-
# ...
|
17
15
|
```
|
18
16
|
|
19
17
|
ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
|
@@ -22,6 +20,33 @@ ElementHandle prevents DOM element from garbage collection unless the handle is
|
|
22
20
|
ElementHandle instances can be used as an argument in [Page#eval_on_selector](./page#eval_on_selector) and [Page#evaluate](./page#evaluate)
|
23
21
|
methods.
|
24
22
|
|
23
|
+
> NOTE: In most cases, you would want to use the [Locator](./locator) object instead. You should only use [ElementHandle](./element_handle) if you
|
24
|
+
want to retain a handle to a particular DOM Node that you intend to pass into [Page#evaluate](./page#evaluate) as an argument.
|
25
|
+
|
26
|
+
The difference between the [Locator](./locator) and ElementHandle is that the ElementHandle points to a particular element, while
|
27
|
+
[Locator](./locator) captures the logic of how to retrieve an element.
|
28
|
+
|
29
|
+
In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
|
30
|
+
React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
|
31
|
+
unexpected behaviors.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
handle = page.query_selector("text=Submit")
|
35
|
+
handle.hover
|
36
|
+
handle.click
|
37
|
+
```
|
38
|
+
|
39
|
+
With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
|
40
|
+
in the snippet below, underlying DOM element is going to be located twice.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
locator = page.locator("text=Submit")
|
44
|
+
locator.hover
|
45
|
+
locator.click
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
|
25
50
|
## bounding_box
|
26
51
|
|
27
52
|
```
|
@@ -68,6 +68,7 @@ def check(
|
|
68
68
|
force: nil,
|
69
69
|
noWaitAfter: nil,
|
70
70
|
position: nil,
|
71
|
+
strict: nil,
|
71
72
|
timeout: nil,
|
72
73
|
trial: nil)
|
73
74
|
```
|
@@ -106,6 +107,7 @@ def click(
|
|
106
107
|
modifiers: nil,
|
107
108
|
noWaitAfter: nil,
|
108
109
|
position: nil,
|
110
|
+
strict: nil,
|
109
111
|
timeout: nil,
|
110
112
|
trial: nil)
|
111
113
|
```
|
@@ -140,6 +142,7 @@ def dblclick(
|
|
140
142
|
modifiers: nil,
|
141
143
|
noWaitAfter: nil,
|
142
144
|
position: nil,
|
145
|
+
strict: nil,
|
143
146
|
timeout: nil,
|
144
147
|
trial: nil)
|
145
148
|
```
|
@@ -161,7 +164,12 @@ zero timeout disables this.
|
|
161
164
|
## dispatch_event
|
162
165
|
|
163
166
|
```
|
164
|
-
def dispatch_event(
|
167
|
+
def dispatch_event(
|
168
|
+
selector,
|
169
|
+
type,
|
170
|
+
eventInit: nil,
|
171
|
+
strict: nil,
|
172
|
+
timeout: nil)
|
165
173
|
```
|
166
174
|
|
167
175
|
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
|
@@ -204,6 +212,7 @@ def drag_and_drop(
|
|
204
212
|
target,
|
205
213
|
force: nil,
|
206
214
|
noWaitAfter: nil,
|
215
|
+
strict: nil,
|
207
216
|
timeout: nil,
|
208
217
|
trial: nil)
|
209
218
|
```
|
@@ -213,7 +222,7 @@ def drag_and_drop(
|
|
213
222
|
## eval_on_selector
|
214
223
|
|
215
224
|
```
|
216
|
-
def eval_on_selector(selector, expression, arg: nil)
|
225
|
+
def eval_on_selector(selector, expression, arg: nil, strict: nil)
|
217
226
|
```
|
218
227
|
|
219
228
|
Returns the return value of `expression`.
|
@@ -345,6 +354,7 @@ def fill(
|
|
345
354
|
value,
|
346
355
|
force: nil,
|
347
356
|
noWaitAfter: nil,
|
357
|
+
strict: nil,
|
348
358
|
timeout: nil)
|
349
359
|
```
|
350
360
|
|
@@ -362,7 +372,7 @@ To send fine-grained keyboard events, use [Frame#type](./frame#type).
|
|
362
372
|
## focus
|
363
373
|
|
364
374
|
```
|
365
|
-
def focus(selector, timeout: nil)
|
375
|
+
def focus(selector, strict: nil, timeout: nil)
|
366
376
|
```
|
367
377
|
|
368
378
|
This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
|
@@ -393,7 +403,7 @@ assert frame == content_frame
|
|
393
403
|
## get_attribute
|
394
404
|
|
395
405
|
```
|
396
|
-
def get_attribute(selector, name, timeout: nil)
|
406
|
+
def get_attribute(selector, name, strict: nil, timeout: nil)
|
397
407
|
```
|
398
408
|
|
399
409
|
Returns element attribute value.
|
@@ -431,6 +441,7 @@ def hover(
|
|
431
441
|
force: nil,
|
432
442
|
modifiers: nil,
|
433
443
|
position: nil,
|
444
|
+
strict: nil,
|
434
445
|
timeout: nil,
|
435
446
|
trial: nil)
|
436
447
|
```
|
@@ -449,7 +460,7 @@ zero timeout disables this.
|
|
449
460
|
## inner_html
|
450
461
|
|
451
462
|
```
|
452
|
-
def inner_html(selector, timeout: nil)
|
463
|
+
def inner_html(selector, strict: nil, timeout: nil)
|
453
464
|
```
|
454
465
|
|
455
466
|
Returns `element.innerHTML`.
|
@@ -457,7 +468,7 @@ Returns `element.innerHTML`.
|
|
457
468
|
## inner_text
|
458
469
|
|
459
470
|
```
|
460
|
-
def inner_text(selector, timeout: nil)
|
471
|
+
def inner_text(selector, strict: nil, timeout: nil)
|
461
472
|
```
|
462
473
|
|
463
474
|
Returns `element.innerText`.
|
@@ -465,7 +476,7 @@ Returns `element.innerText`.
|
|
465
476
|
## input_value
|
466
477
|
|
467
478
|
```
|
468
|
-
def input_value(selector, timeout: nil)
|
479
|
+
def input_value(selector, strict: nil, timeout: nil)
|
469
480
|
```
|
470
481
|
|
471
482
|
Returns `input.value` for the selected `<input>` or `<textarea>` element. Throws for non-input elements.
|
@@ -473,7 +484,7 @@ Returns `input.value` for the selected `<input>` or `<textarea>` element. Throws
|
|
473
484
|
## checked?
|
474
485
|
|
475
486
|
```
|
476
|
-
def checked?(selector, timeout: nil)
|
487
|
+
def checked?(selector, strict: nil, timeout: nil)
|
477
488
|
```
|
478
489
|
|
479
490
|
Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
@@ -489,7 +500,7 @@ Returns `true` if the frame has been detached, or `false` otherwise.
|
|
489
500
|
## disabled?
|
490
501
|
|
491
502
|
```
|
492
|
-
def disabled?(selector, timeout: nil)
|
503
|
+
def disabled?(selector, strict: nil, timeout: nil)
|
493
504
|
```
|
494
505
|
|
495
506
|
Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
|
@@ -497,7 +508,7 @@ Returns whether the element is disabled, the opposite of [enabled](https://playw
|
|
497
508
|
## editable?
|
498
509
|
|
499
510
|
```
|
500
|
-
def editable?(selector, timeout: nil)
|
511
|
+
def editable?(selector, strict: nil, timeout: nil)
|
501
512
|
```
|
502
513
|
|
503
514
|
Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
|
@@ -505,7 +516,7 @@ Returns whether the element is [editable](https://playwright.dev/python/docs/act
|
|
505
516
|
## enabled?
|
506
517
|
|
507
518
|
```
|
508
|
-
def enabled?(selector, timeout: nil)
|
519
|
+
def enabled?(selector, strict: nil, timeout: nil)
|
509
520
|
```
|
510
521
|
|
511
522
|
Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
|
@@ -513,7 +524,7 @@ Returns whether the element is [enabled](https://playwright.dev/python/docs/acti
|
|
513
524
|
## hidden?
|
514
525
|
|
515
526
|
```
|
516
|
-
def hidden?(selector, timeout: nil)
|
527
|
+
def hidden?(selector, strict: nil, timeout: nil)
|
517
528
|
```
|
518
529
|
|
519
530
|
Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability). `selector` that does not
|
@@ -522,12 +533,24 @@ match any elements is considered hidden.
|
|
522
533
|
## visible?
|
523
534
|
|
524
535
|
```
|
525
|
-
def visible?(selector, timeout: nil)
|
536
|
+
def visible?(selector, strict: nil, timeout: nil)
|
526
537
|
```
|
527
538
|
|
528
539
|
Returns whether the element is [visible](https://playwright.dev/python/docs/actionability). `selector` that does not match any elements is
|
529
540
|
considered not visible.
|
530
541
|
|
542
|
+
## locator
|
543
|
+
|
544
|
+
```
|
545
|
+
def locator(selector)
|
546
|
+
```
|
547
|
+
|
548
|
+
The method returns an element locator that can be used to perform actions in the frame. Locator is resolved to the
|
549
|
+
element immediately before performing an action, so a series of actions on the same locator can in fact be performed on
|
550
|
+
different DOM elements. That would happen if the DOM structure between those actions has changed.
|
551
|
+
|
552
|
+
Note that locator always implies visibility, so it will always be locating visible elements.
|
553
|
+
|
531
554
|
## name
|
532
555
|
|
533
556
|
```
|
@@ -564,6 +587,7 @@ def press(
|
|
564
587
|
key,
|
565
588
|
delay: nil,
|
566
589
|
noWaitAfter: nil,
|
590
|
+
strict: nil,
|
567
591
|
timeout: nil)
|
568
592
|
```
|
569
593
|
|
@@ -587,7 +611,7 @@ modifier, modifier is pressed and being held while the subsequent key is being p
|
|
587
611
|
## query_selector
|
588
612
|
|
589
613
|
```
|
590
|
-
def query_selector(selector)
|
614
|
+
def query_selector(selector, strict: nil)
|
591
615
|
```
|
592
616
|
|
593
617
|
Returns the ElementHandle pointing to the frame element.
|
@@ -617,6 +641,7 @@ def select_option(
|
|
617
641
|
label: nil,
|
618
642
|
force: nil,
|
619
643
|
noWaitAfter: nil,
|
644
|
+
strict: nil,
|
620
645
|
timeout: nil)
|
621
646
|
```
|
622
647
|
|
@@ -655,7 +680,12 @@ alias: `content=`
|
|
655
680
|
## set_input_files
|
656
681
|
|
657
682
|
```
|
658
|
-
def set_input_files(
|
683
|
+
def set_input_files(
|
684
|
+
selector,
|
685
|
+
files,
|
686
|
+
noWaitAfter: nil,
|
687
|
+
strict: nil,
|
688
|
+
timeout: nil)
|
659
689
|
```
|
660
690
|
|
661
691
|
This method expects `selector` to point to an
|
@@ -673,6 +703,7 @@ def tap_point(
|
|
673
703
|
modifiers: nil,
|
674
704
|
noWaitAfter: nil,
|
675
705
|
position: nil,
|
706
|
+
strict: nil,
|
676
707
|
timeout: nil,
|
677
708
|
trial: nil)
|
678
709
|
```
|
@@ -693,7 +724,7 @@ zero timeout disables this.
|
|
693
724
|
## text_content
|
694
725
|
|
695
726
|
```
|
696
|
-
def text_content(selector, timeout: nil)
|
727
|
+
def text_content(selector, strict: nil, timeout: nil)
|
697
728
|
```
|
698
729
|
|
699
730
|
Returns `element.textContent`.
|
@@ -714,6 +745,7 @@ def type(
|
|
714
745
|
text,
|
715
746
|
delay: nil,
|
716
747
|
noWaitAfter: nil,
|
748
|
+
strict: nil,
|
717
749
|
timeout: nil)
|
718
750
|
```
|
719
751
|
|
@@ -738,6 +770,7 @@ def uncheck(
|
|
738
770
|
force: nil,
|
739
771
|
noWaitAfter: nil,
|
740
772
|
position: nil,
|
773
|
+
strict: nil,
|
741
774
|
timeout: nil,
|
742
775
|
trial: nil)
|
743
776
|
```
|
@@ -845,7 +878,7 @@ considered a navigation.
|
|
845
878
|
## wait_for_selector
|
846
879
|
|
847
880
|
```
|
848
|
-
def wait_for_selector(selector, state: nil, timeout: nil)
|
881
|
+
def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
|
849
882
|
```
|
850
883
|
|
851
884
|
Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
|
@@ -0,0 +1,650 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Locator
|
6
|
+
|
7
|
+
Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
|
8
|
+
given moment. Locator can be created with the [Page#locator](./page#locator) method.
|
9
|
+
|
10
|
+
```python sync title=example_9f72eed0cd4b2405e6a115b812b36ff2624e889f9086925c47665333a7edabbc.py
|
11
|
+
locator = page.locator("text=Submit")
|
12
|
+
locator.click()
|
13
|
+
|
14
|
+
```
|
15
|
+
|
16
|
+
The difference between the Locator and [ElementHandle](./element_handle) is that the latter points to a particular element, while Locator
|
17
|
+
captures the logic of how to retrieve that element.
|
18
|
+
|
19
|
+
In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
|
20
|
+
React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
|
21
|
+
unexpected behaviors.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
handle = page.query_selector("text=Submit")
|
25
|
+
handle.hover
|
26
|
+
handle.click
|
27
|
+
```
|
28
|
+
|
29
|
+
With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
|
30
|
+
in the snippet below, underlying DOM element is going to be located twice.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
locator = page.locator("text=Submit")
|
34
|
+
locator.hover
|
35
|
+
locator.click
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
## all_inner_texts
|
41
|
+
|
42
|
+
```
|
43
|
+
def all_inner_texts
|
44
|
+
```
|
45
|
+
|
46
|
+
Returns an array of `node.innerText` values for all matching nodes.
|
47
|
+
|
48
|
+
## all_text_contents
|
49
|
+
|
50
|
+
```
|
51
|
+
def all_text_contents
|
52
|
+
```
|
53
|
+
|
54
|
+
Returns an array of `node.textContent` values for all matching nodes.
|
55
|
+
|
56
|
+
## bounding_box
|
57
|
+
|
58
|
+
```
|
59
|
+
def bounding_box(timeout: nil)
|
60
|
+
```
|
61
|
+
|
62
|
+
This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
|
63
|
+
calculated relative to the main frame viewport - which is usually the same as the browser window.
|
64
|
+
|
65
|
+
Scrolling affects the returned bonding box, similarly to
|
66
|
+
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
|
67
|
+
means `x` and/or `y` may be negative.
|
68
|
+
|
69
|
+
Elements from child frames return the bounding box relative to the main frame, unlike the
|
70
|
+
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
|
71
|
+
|
72
|
+
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
73
|
+
snippet should click the center of the element.
|
74
|
+
|
75
|
+
```python sync title=example_4d635e937854fa2ee56b7c43151ded535940f0bbafc00cf48e8214bed86715eb.py
|
76
|
+
box = element.bounding_box()
|
77
|
+
page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
## check
|
84
|
+
|
85
|
+
```
|
86
|
+
def check(
|
87
|
+
force: nil,
|
88
|
+
noWaitAfter: nil,
|
89
|
+
position: nil,
|
90
|
+
timeout: nil,
|
91
|
+
trial: nil)
|
92
|
+
```
|
93
|
+
|
94
|
+
This method checks the element by performing the following steps:
|
95
|
+
1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked,
|
96
|
+
this method returns immediately.
|
97
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
98
|
+
1. Scroll the element into view if needed.
|
99
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element.
|
100
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
101
|
+
1. Ensure that the element is now checked. If not, this method throws.
|
102
|
+
|
103
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
104
|
+
|
105
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
106
|
+
zero timeout disables this.
|
107
|
+
|
108
|
+
## click
|
109
|
+
|
110
|
+
```
|
111
|
+
def click(
|
112
|
+
button: nil,
|
113
|
+
clickCount: nil,
|
114
|
+
delay: nil,
|
115
|
+
force: nil,
|
116
|
+
modifiers: nil,
|
117
|
+
noWaitAfter: nil,
|
118
|
+
position: nil,
|
119
|
+
timeout: nil,
|
120
|
+
trial: nil)
|
121
|
+
```
|
122
|
+
|
123
|
+
This method clicks the element by performing the following steps:
|
124
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
125
|
+
1. Scroll the element into view if needed.
|
126
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element, or the specified `position`.
|
127
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
128
|
+
|
129
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
130
|
+
|
131
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
132
|
+
zero timeout disables this.
|
133
|
+
|
134
|
+
## count
|
135
|
+
|
136
|
+
```
|
137
|
+
def count
|
138
|
+
```
|
139
|
+
|
140
|
+
Returns the number of elements matching given selector.
|
141
|
+
|
142
|
+
## dblclick
|
143
|
+
|
144
|
+
```
|
145
|
+
def dblclick(
|
146
|
+
button: nil,
|
147
|
+
delay: nil,
|
148
|
+
force: nil,
|
149
|
+
modifiers: nil,
|
150
|
+
noWaitAfter: nil,
|
151
|
+
position: nil,
|
152
|
+
timeout: nil,
|
153
|
+
trial: nil)
|
154
|
+
```
|
155
|
+
|
156
|
+
This method double clicks the element by performing the following steps:
|
157
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
158
|
+
1. Scroll the element into view if needed.
|
159
|
+
1. Use [Page#mouse](./page#mouse) to double click in the center of the element, or the specified `position`.
|
160
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
|
161
|
+
first click of the `dblclick()` triggers a navigation event, this method will throw.
|
162
|
+
|
163
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
164
|
+
|
165
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
166
|
+
zero timeout disables this.
|
167
|
+
|
168
|
+
> NOTE: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
169
|
+
|
170
|
+
## dispatch_event
|
171
|
+
|
172
|
+
```
|
173
|
+
def dispatch_event(type, eventInit: nil, timeout: nil)
|
174
|
+
```
|
175
|
+
|
176
|
+
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
|
177
|
+
`click` is dispatched. This is equivalent to calling
|
178
|
+
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
179
|
+
|
180
|
+
```python sync title=example_8d92b900a98c237ffdcb102ddc35660e37101bde7d107dc64d97a7edeed62a43.py
|
181
|
+
element.dispatch_event("click")
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
186
|
+
and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
|
187
|
+
|
188
|
+
Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
|
189
|
+
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
|
190
|
+
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
|
191
|
+
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
|
192
|
+
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
|
193
|
+
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
|
194
|
+
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
|
195
|
+
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
|
196
|
+
|
197
|
+
You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
|
198
|
+
|
199
|
+
```python sync title=example_e369442a3ff291ab476da408ef63a63dacf47984dc766ff7189d82008ae2848b.py
|
200
|
+
# note you can only create data_transfer in chromium and firefox
|
201
|
+
data_transfer = page.evaluate_handle("new DataTransfer()")
|
202
|
+
element.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
|
203
|
+
|
204
|
+
```
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
## element_handle
|
209
|
+
|
210
|
+
```
|
211
|
+
def element_handle(timeout: nil)
|
212
|
+
```
|
213
|
+
|
214
|
+
Resolves given locator to the first matching DOM element. If no elements matching the query are visible, waits for them
|
215
|
+
up to a given timeout. If multiple elements match the selector, throws.
|
216
|
+
|
217
|
+
## element_handles
|
218
|
+
|
219
|
+
```
|
220
|
+
def element_handles
|
221
|
+
```
|
222
|
+
|
223
|
+
Resolves given locator to all matching DOM elements.
|
224
|
+
|
225
|
+
## evaluate
|
226
|
+
|
227
|
+
```
|
228
|
+
def evaluate(expression, arg: nil, timeout: nil)
|
229
|
+
```
|
230
|
+
|
231
|
+
Returns the return value of `expression`.
|
232
|
+
|
233
|
+
This method passes this handle as the first argument to `expression`.
|
234
|
+
|
235
|
+
If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then `handle.evaluate` would wait for the promise to resolve and return its value.
|
236
|
+
|
237
|
+
Examples:
|
238
|
+
|
239
|
+
```python sync title=example_df39b3df921f81e7cfb71cd873b76a5e91e46b4aa41e1f164128cb322aa38305.py
|
240
|
+
tweets = page.locator(".tweet .retweets")
|
241
|
+
assert tweets.evaluate("node => node.innerText") == "10 retweets"
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
## evaluate_all
|
248
|
+
|
249
|
+
```
|
250
|
+
def evaluate_all(expression, arg: nil)
|
251
|
+
```
|
252
|
+
|
253
|
+
The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
|
254
|
+
to `expression`. Returns the result of `expression` invocation.
|
255
|
+
|
256
|
+
If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [`Locator.evaluateAll`] would wait for the promise to resolve and return its
|
257
|
+
value.
|
258
|
+
|
259
|
+
Examples:
|
260
|
+
|
261
|
+
```python sync title=example_32478e941514ed28b6ac221e6d54b55cf117038ecac6f4191db676480ab68d44.py
|
262
|
+
elements = page.locator("div")
|
263
|
+
div_counts = elements("(divs, min) => divs.length >= min", 10)
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
## evaluate_handle
|
270
|
+
|
271
|
+
```
|
272
|
+
def evaluate_handle(expression, arg: nil, timeout: nil)
|
273
|
+
```
|
274
|
+
|
275
|
+
Returns the return value of `expression` as a [JSHandle](./js_handle).
|
276
|
+
|
277
|
+
This method passes this handle as the first argument to `expression`.
|
278
|
+
|
279
|
+
The only difference between [Locator#evaluate](./locator#evaluate) and [Locator#evaluate_handle](./locator#evaluate_handle) is that
|
280
|
+
[Locator#evaluate_handle](./locator#evaluate_handle) returns [JSHandle](./js_handle).
|
281
|
+
|
282
|
+
If the function passed to the [Locator#evaluate_handle](./locator#evaluate_handle) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then
|
283
|
+
[Locator#evaluate_handle](./locator#evaluate_handle) would wait for the promise to resolve and return its value.
|
284
|
+
|
285
|
+
See [Page#evaluate_handle](./page#evaluate_handle) for more details.
|
286
|
+
|
287
|
+
## fill
|
288
|
+
|
289
|
+
```
|
290
|
+
def fill(value, force: nil, noWaitAfter: nil, timeout: nil)
|
291
|
+
```
|
292
|
+
|
293
|
+
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the element, fills it and triggers an `input`
|
294
|
+
event after filling. Note that you can pass an empty string to clear the input field.
|
295
|
+
|
296
|
+
If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
|
297
|
+
However, if the element is inside the `<label>` element that has an associated
|
298
|
+
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
|
299
|
+
instead.
|
300
|
+
|
301
|
+
To send fine-grained keyboard events, use [Locator#type](./locator#type).
|
302
|
+
|
303
|
+
## first
|
304
|
+
|
305
|
+
```
|
306
|
+
def first
|
307
|
+
```
|
308
|
+
|
309
|
+
Returns locator to the first matching element.
|
310
|
+
|
311
|
+
## focus
|
312
|
+
|
313
|
+
```
|
314
|
+
def focus(timeout: nil)
|
315
|
+
```
|
316
|
+
|
317
|
+
Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element.
|
318
|
+
|
319
|
+
## get_attribute
|
320
|
+
|
321
|
+
```
|
322
|
+
def get_attribute(name, timeout: nil)
|
323
|
+
```
|
324
|
+
|
325
|
+
Returns element attribute value.
|
326
|
+
|
327
|
+
## hover
|
328
|
+
|
329
|
+
```
|
330
|
+
def hover(
|
331
|
+
force: nil,
|
332
|
+
modifiers: nil,
|
333
|
+
position: nil,
|
334
|
+
timeout: nil,
|
335
|
+
trial: nil)
|
336
|
+
```
|
337
|
+
|
338
|
+
This method hovers over the element by performing the following steps:
|
339
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
340
|
+
1. Scroll the element into view if needed.
|
341
|
+
1. Use [Page#mouse](./page#mouse) to hover over the center of the element, or the specified `position`.
|
342
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
343
|
+
|
344
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
345
|
+
|
346
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
347
|
+
zero timeout disables this.
|
348
|
+
|
349
|
+
## inner_html
|
350
|
+
|
351
|
+
```
|
352
|
+
def inner_html(timeout: nil)
|
353
|
+
```
|
354
|
+
|
355
|
+
Returns the `element.innerHTML`.
|
356
|
+
|
357
|
+
## inner_text
|
358
|
+
|
359
|
+
```
|
360
|
+
def inner_text(timeout: nil)
|
361
|
+
```
|
362
|
+
|
363
|
+
Returns the `element.innerText`.
|
364
|
+
|
365
|
+
## input_value
|
366
|
+
|
367
|
+
```
|
368
|
+
def input_value(timeout: nil)
|
369
|
+
```
|
370
|
+
|
371
|
+
Returns `input.value` for `<input>` or `<textarea>` element. Throws for non-input elements.
|
372
|
+
|
373
|
+
## checked?
|
374
|
+
|
375
|
+
```
|
376
|
+
def checked?(timeout: nil)
|
377
|
+
```
|
378
|
+
|
379
|
+
Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
380
|
+
|
381
|
+
## disabled?
|
382
|
+
|
383
|
+
```
|
384
|
+
def disabled?(timeout: nil)
|
385
|
+
```
|
386
|
+
|
387
|
+
Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
|
388
|
+
|
389
|
+
## editable?
|
390
|
+
|
391
|
+
```
|
392
|
+
def editable?(timeout: nil)
|
393
|
+
```
|
394
|
+
|
395
|
+
Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
|
396
|
+
|
397
|
+
## enabled?
|
398
|
+
|
399
|
+
```
|
400
|
+
def enabled?(timeout: nil)
|
401
|
+
```
|
402
|
+
|
403
|
+
Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
|
404
|
+
|
405
|
+
## hidden?
|
406
|
+
|
407
|
+
```
|
408
|
+
def hidden?(timeout: nil)
|
409
|
+
```
|
410
|
+
|
411
|
+
Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability).
|
412
|
+
|
413
|
+
## visible?
|
414
|
+
|
415
|
+
```
|
416
|
+
def visible?(timeout: nil)
|
417
|
+
```
|
418
|
+
|
419
|
+
Returns whether the element is [visible](https://playwright.dev/python/docs/actionability).
|
420
|
+
|
421
|
+
## last
|
422
|
+
|
423
|
+
```
|
424
|
+
def last
|
425
|
+
```
|
426
|
+
|
427
|
+
Returns locator to the last matching element.
|
428
|
+
|
429
|
+
## locator
|
430
|
+
|
431
|
+
```
|
432
|
+
def locator(selector)
|
433
|
+
```
|
434
|
+
|
435
|
+
The method finds an element matching the specified selector in the [Locator](./locator)'s subtree. See
|
436
|
+
[Working with selectors](https://playwright.dev/python/docs/selectors) for more details.
|
437
|
+
|
438
|
+
## nth
|
439
|
+
|
440
|
+
```
|
441
|
+
def nth(index)
|
442
|
+
```
|
443
|
+
|
444
|
+
Returns locator to the n-th matching element.
|
445
|
+
|
446
|
+
## press
|
447
|
+
|
448
|
+
```
|
449
|
+
def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
|
450
|
+
```
|
451
|
+
|
452
|
+
Focuses the element, and then uses [Keyboard#down](./keyboard#down) and [Keyboard#up](./keyboard#up).
|
453
|
+
|
454
|
+
`key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
|
455
|
+
value or a single character to generate the text for. A superset of the `key` values can be found
|
456
|
+
[here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
|
457
|
+
|
458
|
+
`F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
|
459
|
+
`Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
|
460
|
+
|
461
|
+
Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
|
462
|
+
|
463
|
+
Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
|
464
|
+
|
465
|
+
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
|
466
|
+
texts.
|
467
|
+
|
468
|
+
Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
|
469
|
+
modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
470
|
+
|
471
|
+
## screenshot
|
472
|
+
|
473
|
+
```
|
474
|
+
def screenshot(
|
475
|
+
omitBackground: nil,
|
476
|
+
path: nil,
|
477
|
+
quality: nil,
|
478
|
+
timeout: nil,
|
479
|
+
type: nil)
|
480
|
+
```
|
481
|
+
|
482
|
+
Returns the buffer with the captured screenshot.
|
483
|
+
|
484
|
+
This method waits for the [actionability](https://playwright.dev/python/docs/actionability) checks, then scrolls element into view before taking a
|
485
|
+
screenshot. If the element is detached from DOM, the method throws an error.
|
486
|
+
|
487
|
+
## scroll_into_view_if_needed
|
488
|
+
|
489
|
+
```
|
490
|
+
def scroll_into_view_if_needed(timeout: nil)
|
491
|
+
```
|
492
|
+
|
493
|
+
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then tries to scroll element into view, unless it is
|
494
|
+
completely visible as defined by
|
495
|
+
[IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
|
496
|
+
|
497
|
+
## select_option
|
498
|
+
|
499
|
+
```
|
500
|
+
def select_option(
|
501
|
+
element: nil,
|
502
|
+
index: nil,
|
503
|
+
value: nil,
|
504
|
+
label: nil,
|
505
|
+
force: nil,
|
506
|
+
noWaitAfter: nil,
|
507
|
+
timeout: nil)
|
508
|
+
```
|
509
|
+
|
510
|
+
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, waits until all specified options are present in the
|
511
|
+
`<select>` element and selects these options.
|
512
|
+
|
513
|
+
If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
|
514
|
+
`<label>` element that has an associated
|
515
|
+
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
|
516
|
+
|
517
|
+
Returns the array of option values that have been successfully selected.
|
518
|
+
|
519
|
+
Triggers a `change` and `input` event once all the provided options have been selected.
|
520
|
+
|
521
|
+
```python sync title=example_2825b0a50091868d1ce3ea0752d94ba32d826d504c1ac6842522796ca405913e.py
|
522
|
+
# single selection matching the value
|
523
|
+
element.select_option("blue")
|
524
|
+
# single selection matching both the label
|
525
|
+
element.select_option(label="blue")
|
526
|
+
# multiple selection
|
527
|
+
element.select_option(value=["red", "green", "blue"])
|
528
|
+
|
529
|
+
```
|
530
|
+
|
531
|
+
```python sync title=example_3aaff4985dc38e64fad34696c88a6a68a633e26aabee6fc749125f3ee1784e34.py
|
532
|
+
# single selection matching the value
|
533
|
+
element.select_option("blue")
|
534
|
+
# single selection matching both the value and the label
|
535
|
+
element.select_option(label="blue")
|
536
|
+
# multiple selection
|
537
|
+
element.select_option("red", "green", "blue")
|
538
|
+
# multiple selection for blue, red and second option
|
539
|
+
element.select_option(value="blue", { index: 2 }, "red")
|
540
|
+
|
541
|
+
```
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
## select_text
|
546
|
+
|
547
|
+
```
|
548
|
+
def select_text(force: nil, timeout: nil)
|
549
|
+
```
|
550
|
+
|
551
|
+
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then focuses the element and selects all its text
|
552
|
+
content.
|
553
|
+
|
554
|
+
## set_input_files
|
555
|
+
|
556
|
+
```
|
557
|
+
def set_input_files(files, noWaitAfter: nil, timeout: nil)
|
558
|
+
```
|
559
|
+
alias: `input_files=`
|
560
|
+
|
561
|
+
This method expects `element` to point to an
|
562
|
+
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
563
|
+
|
564
|
+
Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
|
565
|
+
are resolved relative to the the current working directory. For empty array, clears the selected files.
|
566
|
+
|
567
|
+
## tap_point
|
568
|
+
|
569
|
+
```
|
570
|
+
def tap_point(
|
571
|
+
force: nil,
|
572
|
+
modifiers: nil,
|
573
|
+
noWaitAfter: nil,
|
574
|
+
position: nil,
|
575
|
+
timeout: nil,
|
576
|
+
trial: nil)
|
577
|
+
```
|
578
|
+
|
579
|
+
This method taps the element by performing the following steps:
|
580
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
581
|
+
1. Scroll the element into view if needed.
|
582
|
+
1. Use [Page#touchscreen](./page#touchscreen) to tap the center of the element, or the specified `position`.
|
583
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
584
|
+
|
585
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
586
|
+
|
587
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
588
|
+
zero timeout disables this.
|
589
|
+
|
590
|
+
> NOTE: `element.tap()` requires that the `hasTouch` option of the browser context be set to true.
|
591
|
+
|
592
|
+
## text_content
|
593
|
+
|
594
|
+
```
|
595
|
+
def text_content(timeout: nil)
|
596
|
+
```
|
597
|
+
|
598
|
+
Returns the `node.textContent`.
|
599
|
+
|
600
|
+
## type
|
601
|
+
|
602
|
+
```
|
603
|
+
def type(text, delay: nil, noWaitAfter: nil, timeout: nil)
|
604
|
+
```
|
605
|
+
|
606
|
+
Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
607
|
+
|
608
|
+
To press a special key, like `Control` or `ArrowDown`, use [Locator#press](./locator#press).
|
609
|
+
|
610
|
+
```python sync title=example_fa1712c0b6ceb96fcaa74790d33f2c2eefe2bd1f06e61b78e0bb84a6f22c7961.py
|
611
|
+
element.type("hello") # types instantly
|
612
|
+
element.type("world", delay=100) # types slower, like a user
|
613
|
+
|
614
|
+
```
|
615
|
+
|
616
|
+
An example of typing into a text field and then submitting the form:
|
617
|
+
|
618
|
+
```python sync title=example_adefe90dee78708d4375c20f081f12f2b71f2becb472a2e0d4fdc8cc49c37809.py
|
619
|
+
element = page.locator("input")
|
620
|
+
element.type("some text")
|
621
|
+
element.press("Enter")
|
622
|
+
|
623
|
+
```
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
## uncheck
|
628
|
+
|
629
|
+
```
|
630
|
+
def uncheck(
|
631
|
+
force: nil,
|
632
|
+
noWaitAfter: nil,
|
633
|
+
position: nil,
|
634
|
+
timeout: nil,
|
635
|
+
trial: nil)
|
636
|
+
```
|
637
|
+
|
638
|
+
This method checks the element by performing the following steps:
|
639
|
+
1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
|
640
|
+
unchecked, this method returns immediately.
|
641
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the element, unless `force` option is set.
|
642
|
+
1. Scroll the element into view if needed.
|
643
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element.
|
644
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
645
|
+
1. Ensure that the element is now unchecked. If not, this method throws.
|
646
|
+
|
647
|
+
If the element is detached from the DOM at any moment during the action, this method throws.
|
648
|
+
|
649
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
650
|
+
zero timeout disables this.
|