playwright-ruby-client 1.14.beta3 → 1.15.beta3
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.
- checksums.yaml +4 -4
- data/README.md +10 -14
- data/documentation/docs/api/browser.md +4 -0
- data/documentation/docs/api/browser_context.md +5 -1
- data/documentation/docs/api/browser_type.md +2 -0
- data/documentation/docs/api/element_handle.md +30 -5
- data/documentation/docs/api/experimental/android_device.md +2 -0
- data/documentation/docs/api/frame.md +32 -6
- data/documentation/docs/api/locator.md +67 -38
- data/documentation/docs/api/mouse.md +11 -0
- data/documentation/docs/api/page.md +38 -7
- data/documentation/docs/api/request.md +34 -1
- data/documentation/docs/api/response.md +37 -2
- data/documentation/docs/api/selectors.md +29 -3
- data/documentation/docs/api/tracing.md +42 -8
- data/documentation/docs/api/worker.md +12 -11
- data/documentation/docs/article/getting_started.md +10 -1
- data/documentation/docs/article/guides/download_playwright_driver.md +9 -0
- data/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +56 -3
- data/documentation/docs/article/guides/rails_integration.md +4 -2
- data/documentation/docs/article/guides/rails_integration_with_null_driver.md +86 -0
- data/documentation/docs/article/guides/recording_video.md +1 -1
- data/documentation/docs/article/guides/semi_automation.md +2 -2
- data/documentation/docs/article/guides/use_storage_state.md +78 -0
- data/documentation/docs/include/api_coverage.md +15 -0
- data/documentation/docusaurus.config.js +1 -0
- data/documentation/package.json +2 -2
- data/documentation/src/pages/index.js +0 -1
- data/documentation/static/img/playwright-ruby-client.png +0 -0
- data/documentation/yarn.lock +625 -549
- data/lib/playwright/channel.rb +36 -2
- data/lib/playwright/channel_owners/artifact.rb +6 -2
- data/lib/playwright/channel_owners/browser.rb +4 -0
- data/lib/playwright/channel_owners/browser_context.rb +21 -14
- data/lib/playwright/channel_owners/browser_type.rb +0 -1
- data/lib/playwright/channel_owners/element_handle.rb +10 -2
- data/lib/playwright/channel_owners/frame.rb +8 -0
- data/lib/playwright/channel_owners/page.rb +20 -4
- data/lib/playwright/channel_owners/playwright.rb +9 -0
- data/lib/playwright/channel_owners/request.rb +53 -17
- data/lib/playwright/channel_owners/response.rb +48 -5
- data/lib/playwright/connection.rb +8 -11
- data/lib/playwright/http_headers.rb +0 -6
- data/lib/playwright/locator_impl.rb +8 -0
- data/lib/playwright/mouse_impl.rb +9 -0
- data/lib/playwright/raw_headers.rb +61 -0
- data/lib/playwright/{route_handler_entry.rb → route_handler.rb} +30 -2
- data/lib/playwright/tracing_impl.rb +18 -7
- data/lib/playwright/transport.rb +2 -0
- data/lib/playwright/utils.rb +8 -1
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright/web_socket_transport.rb +2 -0
- data/lib/playwright.rb +46 -5
- data/lib/playwright_api/android.rb +6 -6
- data/lib/playwright_api/android_device.rb +11 -9
- data/lib/playwright_api/browser.rb +12 -8
- data/lib/playwright_api/browser_context.rb +12 -8
- data/lib/playwright_api/browser_type.rb +9 -7
- data/lib/playwright_api/cdp_session.rb +7 -7
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +31 -8
- data/lib/playwright_api/frame.rb +35 -12
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +39 -0
- data/lib/playwright_api/mouse.rb +8 -0
- data/lib/playwright_api/page.rb +43 -15
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +33 -7
- data/lib/playwright_api/response.rb +31 -8
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +38 -7
- data/lib/playwright_api/tracing.rb +33 -4
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '028909fb1fc1321105a1172d46c02ccafbb071e5e630b5c5b616a9e76a695a91'
|
4
|
+
data.tar.gz: cadf29fb85714aac062c481b0c677709dc620141af57b0641d065a379210e93b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efe23218fd7aa8a5eee431af6fac5046420b222f67e196cd46cf44127bafe6a4db88f3ae56f71b1fe74d874fd385f1600009335e59be9c2a5bbca0ad4eacd13a
|
7
|
+
data.tar.gz: d0c78be5d3f3c662cd4b68bbbbf5624ce9febdf4be39740812f26573f14e68c5111fef7777b7ae2a5839c1723d3d20b91d680a2d691c791afcec01efe3630de2
|
data/README.md
CHANGED
@@ -6,19 +6,13 @@
|
|
6
6
|
|
7
7
|
## Getting Started
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
```sh
|
12
|
-
npx playwright install
|
9
|
+
```
|
10
|
+
gem 'playwright-ruby-client'
|
13
11
|
```
|
14
12
|
|
15
|
-
and then
|
16
|
-
|
17
|
-
**Prefer npm install instead of npx?**
|
18
|
-
|
19
|
-
Actually `npx playwright` is a bit slow. We can also use `npm install` to setup.
|
13
|
+
and then 'bundle install'.
|
20
14
|
|
21
|
-
|
15
|
+
Since playwright-ruby-client doesn't include the playwright driver, **we have to install [playwright](https://github.com/microsoft/playwright) in advance**.
|
22
16
|
|
23
17
|
```
|
24
18
|
npm install playwright
|
@@ -29,14 +23,14 @@ And set `playwright_cli_executable_path: './node_modules/.bin/playwright'`
|
|
29
23
|
|
30
24
|
**Prefer playwrighting without Node.js?**
|
31
25
|
|
32
|
-
Instead of npm, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/
|
26
|
+
Instead of npm, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/cb5409934629adaabc0cff1891080de2052fa778/setup.py#L73-L77)
|
33
27
|
|
34
28
|
### Capture a site
|
35
29
|
|
36
30
|
```ruby
|
37
31
|
require 'playwright'
|
38
32
|
|
39
|
-
Playwright.create(playwright_cli_executable_path: '
|
33
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
40
34
|
playwright.chromium.launch(headless: false) do |browser|
|
41
35
|
page = browser.new_page
|
42
36
|
page.goto('https://github.com/YusukeIwaki')
|
@@ -52,7 +46,7 @@ end
|
|
52
46
|
```ruby
|
53
47
|
require 'playwright'
|
54
48
|
|
55
|
-
Playwright.create(playwright_cli_executable_path: '
|
49
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
56
50
|
playwright.chromium.launch(headless: false) do |browser|
|
57
51
|
page = browser.new_page
|
58
52
|
page.goto('https://github.com/')
|
@@ -94,7 +88,7 @@ $ bundle exec ruby main.rb
|
|
94
88
|
```ruby
|
95
89
|
require 'playwright'
|
96
90
|
|
97
|
-
Playwright.create(playwright_cli_executable_path: '
|
91
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
98
92
|
devices = playwright.android.devices
|
99
93
|
unless devices.empty?
|
100
94
|
device = devices.last
|
@@ -185,6 +179,8 @@ end
|
|
185
179
|
|
186
180
|
When `Playwright.connect_to_playwright_server` is used, playwright_cli_executable_path is not required.
|
187
181
|
|
182
|
+
For more detailed instraction, refer this article: https://playwright-ruby-client.vercel.app/docs/article/guides/playwright_on_alpine_linux
|
183
|
+
|
188
184
|
## License
|
189
185
|
|
190
186
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -81,6 +81,7 @@ def new_context(
|
|
81
81
|
colorScheme: nil,
|
82
82
|
deviceScaleFactor: nil,
|
83
83
|
extraHTTPHeaders: nil,
|
84
|
+
forcedColors: nil,
|
84
85
|
geolocation: nil,
|
85
86
|
hasTouch: nil,
|
86
87
|
httpCredentials: nil,
|
@@ -99,6 +100,7 @@ def new_context(
|
|
99
100
|
reducedMotion: nil,
|
100
101
|
screen: nil,
|
101
102
|
storageState: nil,
|
103
|
+
strictSelectors: nil,
|
102
104
|
timezoneId: nil,
|
103
105
|
userAgent: nil,
|
104
106
|
viewport: nil,
|
@@ -130,6 +132,7 @@ def new_page(
|
|
130
132
|
colorScheme: nil,
|
131
133
|
deviceScaleFactor: nil,
|
132
134
|
extraHTTPHeaders: nil,
|
135
|
+
forcedColors: nil,
|
133
136
|
geolocation: nil,
|
134
137
|
hasTouch: nil,
|
135
138
|
httpCredentials: nil,
|
@@ -148,6 +151,7 @@ def new_page(
|
|
148
151
|
reducedMotion: nil,
|
149
152
|
screen: nil,
|
150
153
|
storageState: nil,
|
154
|
+
strictSelectors: nil,
|
151
155
|
timezoneId: nil,
|
152
156
|
userAgent: nil,
|
153
157
|
viewport: nil,
|
@@ -265,12 +265,16 @@ Returns all open pages in the context.
|
|
265
265
|
## route
|
266
266
|
|
267
267
|
```
|
268
|
-
def route(url, handler)
|
268
|
+
def route(url, handler, times: nil)
|
269
269
|
```
|
270
270
|
|
271
271
|
Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
272
272
|
is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
273
273
|
|
274
|
+
> NOTE: [Page#route](./page#route) will not intercept requests intercepted by Service Worker. See
|
275
|
+
[this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
|
276
|
+
request interception. Via `await context.addInitScript(() => delete window.navigator.serviceWorker);`
|
277
|
+
|
274
278
|
An example of a naive handler that aborts all image requests:
|
275
279
|
|
276
280
|
```ruby
|
@@ -114,6 +114,7 @@ def launch_persistent_context(
|
|
114
114
|
env: nil,
|
115
115
|
executablePath: nil,
|
116
116
|
extraHTTPHeaders: nil,
|
117
|
+
forcedColors: nil,
|
117
118
|
geolocation: nil,
|
118
119
|
handleSIGHUP: nil,
|
119
120
|
handleSIGINT: nil,
|
@@ -137,6 +138,7 @@ def launch_persistent_context(
|
|
137
138
|
reducedMotion: nil,
|
138
139
|
screen: nil,
|
139
140
|
slowMo: nil,
|
141
|
+
strictSelectors: nil,
|
140
142
|
timeout: nil,
|
141
143
|
timezoneId: nil,
|
142
144
|
tracesDir: nil,
|
@@ -510,6 +510,32 @@ def select_text(force: nil, timeout: nil)
|
|
510
510
|
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then focuses the element and selects all its text
|
511
511
|
content.
|
512
512
|
|
513
|
+
## set_checked
|
514
|
+
|
515
|
+
```
|
516
|
+
def set_checked(
|
517
|
+
checked,
|
518
|
+
force: nil,
|
519
|
+
noWaitAfter: nil,
|
520
|
+
position: nil,
|
521
|
+
timeout: nil,
|
522
|
+
trial: nil)
|
523
|
+
```
|
524
|
+
alias: `checked=`
|
525
|
+
|
526
|
+
This method checks or unchecks an element by performing the following steps:
|
527
|
+
1. Ensure that element is a checkbox or a radio input. If not, this method throws.
|
528
|
+
1. If the element already has the right checked state, this method returns immediately.
|
529
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
|
530
|
+
element is detached during the checks, the whole action is retried.
|
531
|
+
1. Scroll the element into view if needed.
|
532
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element.
|
533
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
534
|
+
1. Ensure that the element is now checked or unchecked. If not, this method throws.
|
535
|
+
|
536
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
537
|
+
zero timeout disables this.
|
538
|
+
|
513
539
|
## set_input_files
|
514
540
|
|
515
541
|
```
|
@@ -630,7 +656,7 @@ If the element does not satisfy the condition for the `timeout` milliseconds, th
|
|
630
656
|
## wait_for_selector
|
631
657
|
|
632
658
|
```
|
633
|
-
def wait_for_selector(selector, state: nil, timeout: nil)
|
659
|
+
def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
|
634
660
|
```
|
635
661
|
|
636
662
|
Returns element specified by selector when it satisfies `state` option. Returns `null` if waiting for `hidden` or
|
@@ -641,12 +667,11 @@ become visible/hidden). If at the moment of calling the method `selector` alread
|
|
641
667
|
will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will
|
642
668
|
throw.
|
643
669
|
|
644
|
-
```
|
645
|
-
page.
|
670
|
+
```ruby
|
671
|
+
page.content = "<div><span></span></div>"
|
646
672
|
div = page.query_selector("div")
|
647
673
|
# waiting for the "span" selector relative to the div.
|
648
|
-
span = div.wait_for_selector("span", state
|
649
|
-
|
674
|
+
span = div.wait_for_selector("span", state: "attached")
|
650
675
|
```
|
651
676
|
|
652
677
|
> NOTE: This method does not work across navigations, use [Page#wait_for_selector](./page#wait_for_selector) instead.
|
@@ -34,6 +34,7 @@ def launch_browser(
|
|
34
34
|
command: nil,
|
35
35
|
deviceScaleFactor: nil,
|
36
36
|
extraHTTPHeaders: nil,
|
37
|
+
forcedColors: nil,
|
37
38
|
geolocation: nil,
|
38
39
|
hasTouch: nil,
|
39
40
|
httpCredentials: nil,
|
@@ -50,6 +51,7 @@ def launch_browser(
|
|
50
51
|
record_video_size: nil,
|
51
52
|
reducedMotion: nil,
|
52
53
|
screen: nil,
|
54
|
+
strictSelectors: nil,
|
53
55
|
timezoneId: nil,
|
54
56
|
userAgent: nil,
|
55
57
|
viewport: nil,
|
@@ -401,18 +401,18 @@ def goto(url, referer: nil, timeout: nil, waitUntil: nil)
|
|
401
401
|
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
|
402
402
|
last redirect.
|
403
403
|
|
404
|
-
|
404
|
+
The method will throw an error if:
|
405
405
|
- there's an SSL error (e.g. in case of self-signed certificates).
|
406
406
|
- target URL is invalid.
|
407
407
|
- the `timeout` is exceeded during navigation.
|
408
408
|
- the remote server does not respond or is unreachable.
|
409
409
|
- the main resource failed to load.
|
410
410
|
|
411
|
-
|
412
|
-
|
411
|
+
The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
|
412
|
+
Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
|
413
413
|
[Response#status](./response#status).
|
414
414
|
|
415
|
-
> NOTE:
|
415
|
+
> NOTE: The method either throws an error or returns a main resource response. The only exceptions are navigation to
|
416
416
|
`about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
|
417
417
|
> NOTE: Headless mode doesn't support navigation to a PDF document. See the
|
418
418
|
[upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
|
@@ -533,8 +533,6 @@ The method returns an element locator that can be used to perform actions in the
|
|
533
533
|
element immediately before performing an action, so a series of actions on the same locator can in fact be performed on
|
534
534
|
different DOM elements. That would happen if the DOM structure between those actions has changed.
|
535
535
|
|
536
|
-
Note that locator always implies visibility, so it will always be locating visible elements.
|
537
|
-
|
538
536
|
## name
|
539
537
|
|
540
538
|
```
|
@@ -651,6 +649,34 @@ frame.select_option("select#colors", value: ["red", "green", "blue"])
|
|
651
649
|
|
652
650
|
|
653
651
|
|
652
|
+
## set_checked
|
653
|
+
|
654
|
+
```
|
655
|
+
def set_checked(
|
656
|
+
selector,
|
657
|
+
checked,
|
658
|
+
force: nil,
|
659
|
+
noWaitAfter: nil,
|
660
|
+
position: nil,
|
661
|
+
strict: nil,
|
662
|
+
timeout: nil,
|
663
|
+
trial: nil)
|
664
|
+
```
|
665
|
+
|
666
|
+
This method checks or unchecks an element matching `selector` by performing the following steps:
|
667
|
+
1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
|
668
|
+
1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
|
669
|
+
1. If the element already has the right checked state, this method returns immediately.
|
670
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
|
671
|
+
element is detached during the checks, the whole action is retried.
|
672
|
+
1. Scroll the element into view if needed.
|
673
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element.
|
674
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
675
|
+
1. Ensure that the element is now checked or unchecked. If not, this method throws.
|
676
|
+
|
677
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
678
|
+
zero timeout disables this.
|
679
|
+
|
654
680
|
## set_content
|
655
681
|
|
656
682
|
```
|
@@ -7,10 +7,9 @@ sidebar_position: 10
|
|
7
7
|
Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
|
8
8
|
given moment. Locator can be created with the [Page#locator](./page#locator) method.
|
9
9
|
|
10
|
-
```
|
10
|
+
```ruby
|
11
11
|
locator = page.locator("text=Submit")
|
12
|
-
locator.click
|
13
|
-
|
12
|
+
locator.click
|
14
13
|
```
|
15
14
|
|
16
15
|
The difference between the Locator and [ElementHandle](./element_handle) is that the latter points to a particular element, while Locator
|
@@ -35,6 +34,22 @@ locator.hover
|
|
35
34
|
locator.click
|
36
35
|
```
|
37
36
|
|
37
|
+
**Strictness**
|
38
|
+
|
39
|
+
Locators are strict. This means that all operations on locators that imply some target DOM element will throw if more
|
40
|
+
than one element matches given selector.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# Throws if there are several buttons in DOM:
|
44
|
+
page.locator('button').click
|
45
|
+
|
46
|
+
# Works because we explicitly tell locator to pick the first element:
|
47
|
+
page.locator('button').first.click
|
48
|
+
|
49
|
+
# Works because count knows what to do with multiple matches:
|
50
|
+
page.locator('button').count
|
51
|
+
```
|
52
|
+
|
38
53
|
|
39
54
|
|
40
55
|
## all_inner_texts
|
@@ -72,10 +87,12 @@ Elements from child frames return the bounding box relative to the main frame, u
|
|
72
87
|
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
73
88
|
snippet should click the center of the element.
|
74
89
|
|
75
|
-
```
|
76
|
-
box = element.bounding_box
|
77
|
-
page.mouse.click(
|
78
|
-
|
90
|
+
```ruby
|
91
|
+
box = element.bounding_box
|
92
|
+
page.mouse.click(
|
93
|
+
box["x"] + box["width"] / 2,
|
94
|
+
box["y"] + box["height"] / 2,
|
95
|
+
)
|
79
96
|
```
|
80
97
|
|
81
98
|
|
@@ -177,9 +194,8 @@ The snippet below dispatches the `click` event on the element. Regardless of the
|
|
177
194
|
`click` is dispatched. This is equivalent to calling
|
178
195
|
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
179
196
|
|
180
|
-
```
|
197
|
+
```ruby
|
181
198
|
element.dispatch_event("click")
|
182
|
-
|
183
199
|
```
|
184
200
|
|
185
201
|
Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
@@ -196,11 +212,10 @@ Since `eventInit` is event-specific, please refer to the events documentation fo
|
|
196
212
|
|
197
213
|
You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
|
198
214
|
|
199
|
-
```
|
215
|
+
```ruby
|
200
216
|
# note you can only create data_transfer in chromium and firefox
|
201
217
|
data_transfer = page.evaluate_handle("new DataTransfer()")
|
202
|
-
element.dispatch_event("
|
203
|
-
|
218
|
+
element.dispatch_event("dragstart", eventInit: { dataTransfer: data_transfer })
|
204
219
|
```
|
205
220
|
|
206
221
|
|
@@ -236,10 +251,9 @@ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web
|
|
236
251
|
|
237
252
|
Examples:
|
238
253
|
|
239
|
-
```
|
240
|
-
|
241
|
-
|
242
|
-
|
254
|
+
```ruby
|
255
|
+
tweet = page.query_selector(".tweet .retweets")
|
256
|
+
tweet.evaluate("node => node.innerText") # => "10 retweets"
|
243
257
|
```
|
244
258
|
|
245
259
|
|
@@ -258,10 +272,9 @@ return its value.
|
|
258
272
|
|
259
273
|
Examples:
|
260
274
|
|
261
|
-
```
|
275
|
+
```ruby
|
262
276
|
elements = page.locator("div")
|
263
|
-
|
264
|
-
|
277
|
+
elements.evaluate_all("(divs, min) => divs.length >= min", arg: 10)
|
265
278
|
```
|
266
279
|
|
267
280
|
|
@@ -518,26 +531,18 @@ Returns the array of option values that have been successfully selected.
|
|
518
531
|
|
519
532
|
Triggers a `change` and `input` event once all the provided options have been selected.
|
520
533
|
|
521
|
-
```
|
534
|
+
```ruby
|
522
535
|
# single selection matching the value
|
523
|
-
element.select_option("blue")
|
536
|
+
element.select_option(value: "blue")
|
524
537
|
# single selection matching both the label
|
525
|
-
element.select_option(label
|
538
|
+
element.select_option(label: "blue")
|
526
539
|
# multiple selection
|
527
|
-
element.select_option(value
|
528
|
-
|
540
|
+
element.select_option(value: ["red", "green", "blue"])
|
529
541
|
```
|
530
542
|
|
531
|
-
```
|
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")
|
543
|
+
```ruby
|
538
544
|
# multiple selection for blue, red and second option
|
539
|
-
element.select_option(value
|
540
|
-
|
545
|
+
element.select_option(value: "blue", index: 2, label: "red")
|
541
546
|
```
|
542
547
|
|
543
548
|
|
@@ -551,6 +556,32 @@ def select_text(force: nil, timeout: nil)
|
|
551
556
|
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then focuses the element and selects all its text
|
552
557
|
content.
|
553
558
|
|
559
|
+
## set_checked
|
560
|
+
|
561
|
+
```
|
562
|
+
def set_checked(
|
563
|
+
checked,
|
564
|
+
force: nil,
|
565
|
+
noWaitAfter: nil,
|
566
|
+
position: nil,
|
567
|
+
timeout: nil,
|
568
|
+
trial: nil)
|
569
|
+
```
|
570
|
+
alias: `checked=`
|
571
|
+
|
572
|
+
This method checks or unchecks an element by performing the following steps:
|
573
|
+
1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
|
574
|
+
1. If the element already has the right checked state, this method returns immediately.
|
575
|
+
1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
|
576
|
+
element is detached during the checks, the whole action is retried.
|
577
|
+
1. Scroll the element into view if needed.
|
578
|
+
1. Use [Page#mouse](./page#mouse) to click in the center of the element.
|
579
|
+
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
|
580
|
+
1. Ensure that the element is now checked or unchecked. If not, this method throws.
|
581
|
+
|
582
|
+
When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
|
583
|
+
zero timeout disables this.
|
584
|
+
|
554
585
|
## set_input_files
|
555
586
|
|
556
587
|
```
|
@@ -607,19 +638,17 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`
|
|
607
638
|
|
608
639
|
To press a special key, like `Control` or `ArrowDown`, use [Locator#press](./locator#press).
|
609
640
|
|
610
|
-
```
|
641
|
+
```ruby
|
611
642
|
element.type("hello") # types instantly
|
612
|
-
element.type("world", delay
|
613
|
-
|
643
|
+
element.type("world", delay: 100) # types slower, like a user
|
614
644
|
```
|
615
645
|
|
616
646
|
An example of typing into a text field and then submitting the form:
|
617
647
|
|
618
|
-
```
|
648
|
+
```ruby
|
619
649
|
element = page.locator("input")
|
620
650
|
element.type("some text")
|
621
651
|
element.press("Enter")
|
622
|
-
|
623
652
|
```
|
624
653
|
|
625
654
|
|