playwright-ruby-client 1.25.0 → 1.27.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/api_request_context.md +93 -0
- data/documentation/docs/api/browser_context.md +3 -3
- data/documentation/docs/api/browser_type.md +8 -0
- data/documentation/docs/api/download.md +1 -1
- data/documentation/docs/api/element_handle.md +1 -1
- data/documentation/docs/api/file_chooser.md +1 -1
- data/documentation/docs/api/frame.md +103 -4
- data/documentation/docs/api/frame_locator.md +105 -5
- data/documentation/docs/api/locator.md +121 -6
- data/documentation/docs/api/page.md +119 -10
- data/documentation/docs/api/tracing.md +1 -1
- data/documentation/docs/article/guides/rails_integration_with_null_driver.md +59 -0
- data/documentation/docs/include/api_coverage.md +29 -0
- data/documentation/src/components/HomepageFeatures.js +1 -1
- data/lib/playwright/channel_owners/api_request_context.rb +23 -120
- data/lib/playwright/channel_owners/browser_context.rb +4 -5
- data/lib/playwright/channel_owners/dialog.rb +1 -1
- data/lib/playwright/channel_owners/frame.rb +4 -0
- data/lib/playwright/channel_owners/page.rb +7 -6
- data/lib/playwright/channel_owners/selectors.rb +4 -0
- data/lib/playwright/frame_locator_impl.rb +6 -2
- data/lib/playwright/locator_impl.rb +7 -31
- data/lib/playwright/locator_utils.rb +142 -0
- data/lib/playwright/route_handler.rb +2 -2
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/api_request_context.rb +92 -7
- data/lib/playwright_api/browser_context.rb +3 -3
- data/lib/playwright_api/browser_type.rb +6 -0
- data/lib/playwright_api/download.rb +1 -1
- data/lib/playwright_api/element_handle.rb +1 -1
- data/lib/playwright_api/file_chooser.rb +1 -1
- data/lib/playwright_api/frame.rb +78 -4
- data/lib/playwright_api/frame_locator.rb +79 -4
- data/lib/playwright_api/locator.rb +94 -5
- data/lib/playwright_api/page.rb +93 -10
- data/lib/playwright_api/request.rb +4 -4
- data/lib/playwright_api/response.rb +4 -4
- data/lib/playwright_api/selectors.rb +11 -0
- data/lib/playwright_api/tracing.rb +1 -1
- data/lib/playwright_api/worker.rb +4 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9944a15cd23ff09a56c09f396ff276ec366670740f4c79cb553a9dedec346ff8
|
4
|
+
data.tar.gz: 33807cddbf67539e40d8659fd565827a1c0127ccc65c7b6a2864b8e80184053b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ece68b2c84a789d011b00dd17f27a280e26b23349cc474ec04ca00eab18df2a813a1ebda61143603de02f3abec0fc988818122a09a35d57aa101fbb5429c2beb
|
7
|
+
data.tar.gz: 5070dd01c89f50580c98e196e1d97b5ffcc34ab1fc7856ac9943a6bfc4743e418cac2b3632566a88c24f99ed7fad1c0c3f1c7f66f873a76c02b993eb0baf74bc
|
@@ -66,6 +66,7 @@ def delete(
|
|
66
66
|
form: nil,
|
67
67
|
headers: nil,
|
68
68
|
ignoreHTTPSErrors: nil,
|
69
|
+
maxRedirects: nil,
|
69
70
|
multipart: nil,
|
70
71
|
params: nil,
|
71
72
|
timeout: nil)
|
@@ -95,6 +96,7 @@ def fetch(
|
|
95
96
|
form: nil,
|
96
97
|
headers: nil,
|
97
98
|
ignoreHTTPSErrors: nil,
|
99
|
+
maxRedirects: nil,
|
98
100
|
method: nil,
|
99
101
|
multipart: nil,
|
100
102
|
params: nil,
|
@@ -104,14 +106,47 @@ def fetch(
|
|
104
106
|
Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
105
107
|
context cookies from the response. The method will automatically follow redirects.
|
106
108
|
|
109
|
+
JSON objects can be passed directly to the request:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
data = {
|
113
|
+
title: "Book Title",
|
114
|
+
body: "John Doe",
|
115
|
+
}
|
116
|
+
api_request_context.fetch("https://example.com/api/create_book", method: 'post', data: data)
|
117
|
+
```
|
118
|
+
|
119
|
+
The common way to send file(s) in the body of a request is to encode it as form fields with `multipart/form-data`
|
120
|
+
encoding. You can achieve that with Playwright API like this:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
api_request_context.fetch(
|
124
|
+
"https://example.com/api/upload_script",
|
125
|
+
method: 'post',
|
126
|
+
multipart: {
|
127
|
+
fileField: {
|
128
|
+
name: "f.js",
|
129
|
+
mimeType: "text/javascript",
|
130
|
+
buffer: "console.log(2022);",
|
131
|
+
},
|
132
|
+
},
|
133
|
+
)
|
134
|
+
```
|
135
|
+
|
136
|
+
|
137
|
+
|
107
138
|
## get
|
108
139
|
|
109
140
|
```
|
110
141
|
def get(
|
111
142
|
url,
|
143
|
+
data: nil,
|
112
144
|
failOnStatusCode: nil,
|
145
|
+
form: nil,
|
113
146
|
headers: nil,
|
114
147
|
ignoreHTTPSErrors: nil,
|
148
|
+
maxRedirects: nil,
|
149
|
+
multipart: nil,
|
115
150
|
params: nil,
|
116
151
|
timeout: nil)
|
117
152
|
```
|
@@ -120,14 +155,30 @@ Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GE
|
|
120
155
|
method will populate request cookies from the context and update context cookies from the response. The method will
|
121
156
|
automatically follow redirects.
|
122
157
|
|
158
|
+
Request parameters can be configured with `params` option, they will be serialized into the URL search parameters:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
query_params = {
|
162
|
+
isbn: "1234",
|
163
|
+
page: "23"
|
164
|
+
}
|
165
|
+
api_request_context.get("https://example.com/api/get_text", params: query_params)
|
166
|
+
```
|
167
|
+
|
168
|
+
|
169
|
+
|
123
170
|
## head
|
124
171
|
|
125
172
|
```
|
126
173
|
def head(
|
127
174
|
url,
|
175
|
+
data: nil,
|
128
176
|
failOnStatusCode: nil,
|
177
|
+
form: nil,
|
129
178
|
headers: nil,
|
130
179
|
ignoreHTTPSErrors: nil,
|
180
|
+
maxRedirects: nil,
|
181
|
+
multipart: nil,
|
131
182
|
params: nil,
|
132
183
|
timeout: nil)
|
133
184
|
```
|
@@ -146,6 +197,7 @@ def patch(
|
|
146
197
|
form: nil,
|
147
198
|
headers: nil,
|
148
199
|
ignoreHTTPSErrors: nil,
|
200
|
+
maxRedirects: nil,
|
149
201
|
multipart: nil,
|
150
202
|
params: nil,
|
151
203
|
timeout: nil)
|
@@ -165,6 +217,7 @@ def post(
|
|
165
217
|
form: nil,
|
166
218
|
headers: nil,
|
167
219
|
ignoreHTTPSErrors: nil,
|
220
|
+
maxRedirects: nil,
|
168
221
|
multipart: nil,
|
169
222
|
params: nil,
|
170
223
|
timeout: nil)
|
@@ -174,6 +227,45 @@ Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/P
|
|
174
227
|
The method will populate request cookies from the context and update context cookies from the response. The method will
|
175
228
|
automatically follow redirects.
|
176
229
|
|
230
|
+
JSON objects can be passed directly to the request:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
data = {
|
234
|
+
title: "Book Title",
|
235
|
+
body: "John Doe",
|
236
|
+
}
|
237
|
+
api_request_context.post("https://example.com/api/create_book", data: data)
|
238
|
+
```
|
239
|
+
|
240
|
+
To send form data to the server use `form` option. Its value will be encoded into the request body with
|
241
|
+
`application/x-www-form-urlencoded` encoding (see below how to use `multipart/form-data` form encoding to send files):
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
form_data = {
|
245
|
+
title: "Book Title",
|
246
|
+
body: "John Doe",
|
247
|
+
}
|
248
|
+
api_request_context.post("https://example.com/api/find_book", form: form_data)
|
249
|
+
```
|
250
|
+
|
251
|
+
The common way to send file(s) in the body of a request is to upload them as form fields with `multipart/form-data`
|
252
|
+
encoding. You can achieve that with Playwright API like this:
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
api_request_context.post(
|
256
|
+
"https://example.com/api/upload_script",
|
257
|
+
multipart: {
|
258
|
+
fileField: {
|
259
|
+
name: "f.js",
|
260
|
+
mimeType: "text/javascript",
|
261
|
+
buffer: "console.log(2022);",
|
262
|
+
},
|
263
|
+
},
|
264
|
+
)
|
265
|
+
```
|
266
|
+
|
267
|
+
|
268
|
+
|
177
269
|
## put
|
178
270
|
|
179
271
|
```
|
@@ -184,6 +276,7 @@ def put(
|
|
184
276
|
form: nil,
|
185
277
|
headers: nil,
|
186
278
|
ignoreHTTPSErrors: nil,
|
279
|
+
maxRedirects: nil,
|
187
280
|
multipart: nil,
|
188
281
|
params: nil,
|
189
282
|
timeout: nil)
|
@@ -161,7 +161,7 @@ page.content = <<~HTML
|
|
161
161
|
<div></div>
|
162
162
|
HTML
|
163
163
|
|
164
|
-
page.
|
164
|
+
page.get_by_role("button").click
|
165
165
|
```
|
166
166
|
|
167
167
|
An example of passing an element handle:
|
@@ -222,7 +222,7 @@ page.content = <<~HTML
|
|
222
222
|
<button onclick="onClick()">Click me</button>
|
223
223
|
<div></div>
|
224
224
|
HTML
|
225
|
-
page.
|
225
|
+
page.get_by_role("button").click
|
226
226
|
```
|
227
227
|
|
228
228
|
|
@@ -434,7 +434,7 @@ value. Will throw an error if the context closes before the event is fired. Retu
|
|
434
434
|
|
435
435
|
```ruby
|
436
436
|
new_page = browser_context.expect_event('page') do
|
437
|
-
page.
|
437
|
+
page.get_by_role("button").click
|
438
438
|
end
|
439
439
|
```
|
440
440
|
|
@@ -37,6 +37,14 @@ The default browser context is accessible via [Browser#contexts](./browser#conte
|
|
37
37
|
|
38
38
|
> NOTE: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
39
39
|
|
40
|
+
```ruby
|
41
|
+
browser = playwright.chromium.connect_over_cdp("http://localhost:9222")
|
42
|
+
default_context = browser.contexts.first
|
43
|
+
page = default_context.pages.first
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
|
40
48
|
## executable_path
|
41
49
|
|
42
50
|
```
|
@@ -39,7 +39,7 @@ With the locator, every time the `element` is used, up-to-date DOM element is lo
|
|
39
39
|
in the snippet below, underlying DOM element is going to be located twice.
|
40
40
|
|
41
41
|
```ruby
|
42
|
-
locator = page.
|
42
|
+
locator = page.get_by_text("Submit")
|
43
43
|
locator.hover
|
44
44
|
locator.click
|
45
45
|
```
|
@@ -8,7 +8,7 @@ sidebar_position: 10
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
file_chooser = page.expect_file_chooser do
|
11
|
-
page.
|
11
|
+
page.get_by_text("Upload").click # action to trigger file uploading
|
12
12
|
end
|
13
13
|
file_chooser.set_files("myfile.pdf")
|
14
14
|
```
|
@@ -401,7 +401,7 @@ that iframe. Following snippet locates element with text "Submit" in the iframe
|
|
401
401
|
id="my-frame">`:
|
402
402
|
|
403
403
|
```ruby
|
404
|
-
locator = frame.frame_locator("#my-iframe").
|
404
|
+
locator = frame.frame_locator("#my-iframe").get_by_text("Submit")
|
405
405
|
locator.click
|
406
406
|
```
|
407
407
|
|
@@ -415,6 +415,103 @@ def get_attribute(selector, name, strict: nil, timeout: nil)
|
|
415
415
|
|
416
416
|
Returns element attribute value.
|
417
417
|
|
418
|
+
## get_by_alt_text
|
419
|
+
|
420
|
+
```
|
421
|
+
def get_by_alt_text(text, exact: nil)
|
422
|
+
```
|
423
|
+
|
424
|
+
Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
425
|
+
|
426
|
+
```html
|
427
|
+
<img alt='Castle'>
|
428
|
+
```
|
429
|
+
|
430
|
+
|
431
|
+
## get_by_label
|
432
|
+
|
433
|
+
```
|
434
|
+
def get_by_label(text, exact: nil)
|
435
|
+
```
|
436
|
+
|
437
|
+
Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
438
|
+
label text Password in the following DOM:
|
439
|
+
|
440
|
+
```html
|
441
|
+
<label for="password-input">Password:</label>
|
442
|
+
<input id="password-input">
|
443
|
+
```
|
444
|
+
|
445
|
+
|
446
|
+
## get_by_placeholder
|
447
|
+
|
448
|
+
```
|
449
|
+
def get_by_placeholder(text, exact: nil)
|
450
|
+
```
|
451
|
+
|
452
|
+
Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
453
|
+
"Country":
|
454
|
+
|
455
|
+
```html
|
456
|
+
<input placeholder="Country">
|
457
|
+
```
|
458
|
+
|
459
|
+
|
460
|
+
## get_by_role
|
461
|
+
|
462
|
+
```
|
463
|
+
def get_by_role(
|
464
|
+
role,
|
465
|
+
checked: nil,
|
466
|
+
disabled: nil,
|
467
|
+
expanded: nil,
|
468
|
+
includeHidden: nil,
|
469
|
+
level: nil,
|
470
|
+
name: nil,
|
471
|
+
pressed: nil,
|
472
|
+
selected: nil)
|
473
|
+
```
|
474
|
+
|
475
|
+
Allows locating elements by their [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles),
|
476
|
+
[ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and
|
477
|
+
[accessible name](https://w3c.github.io/accname/#dfn-accessible-name). Note that role selector **does not replace**
|
478
|
+
accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
479
|
+
|
480
|
+
Note that many html elements have an implicitly
|
481
|
+
[defined role](https://w3c.github.io/html-aam/#html-element-role-mappings) that is recognized by the role selector. You
|
482
|
+
can find all the [supported roles here](https://www.w3.org/TR/wai-aria-1.2/#role_definitions). ARIA guidelines **do not
|
483
|
+
recommend** duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values.
|
484
|
+
|
485
|
+
## get_by_test_id
|
486
|
+
|
487
|
+
```
|
488
|
+
def get_by_test_id(testId)
|
489
|
+
```
|
490
|
+
|
491
|
+
Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use
|
492
|
+
[Selectors#set_test_id_attribute](./selectors#set_test_id_attribute) to configure a different test id attribute if necessary.
|
493
|
+
|
494
|
+
## get_by_text
|
495
|
+
|
496
|
+
```
|
497
|
+
def get_by_text(text, exact: nil)
|
498
|
+
```
|
499
|
+
|
500
|
+
Allows locating elements that contain given text.
|
501
|
+
|
502
|
+
## get_by_title
|
503
|
+
|
504
|
+
```
|
505
|
+
def get_by_title(text, exact: nil)
|
506
|
+
```
|
507
|
+
|
508
|
+
Allows locating elements by their title. For example, this method will find the button by its title "Submit":
|
509
|
+
|
510
|
+
```html
|
511
|
+
<button title='Place the order'>Order Now</button>
|
512
|
+
```
|
513
|
+
|
514
|
+
|
418
515
|
## goto
|
419
516
|
|
420
517
|
```
|
@@ -555,9 +652,11 @@ considered not visible.
|
|
555
652
|
def locator(selector, has: nil, hasText: nil)
|
556
653
|
```
|
557
654
|
|
558
|
-
The method returns an element locator that can be used to perform actions
|
559
|
-
element immediately before performing an action, so a series of actions on the same locator can in fact be performed
|
560
|
-
different DOM elements. That would happen if the DOM structure between those actions has changed.
|
655
|
+
The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to
|
656
|
+
the element immediately before performing an action, so a series of actions on the same locator can in fact be performed
|
657
|
+
on different DOM elements. That would happen if the DOM structure between those actions has changed.
|
658
|
+
|
659
|
+
[Learn more about locators](https://playwright.dev/python/docs/locators).
|
561
660
|
|
562
661
|
[Learn more about locators](https://playwright.dev/python/docs/locators).
|
563
662
|
|
@@ -9,21 +9,21 @@ and locate elements in that iframe. FrameLocator can be created with either [Pag
|
|
9
9
|
[Locator#frame_locator](./locator#frame_locator) method.
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
locator = page.frame_locator("my-frame").
|
12
|
+
locator = page.frame_locator("my-frame").get_by_text("Submit")
|
13
13
|
locator.click
|
14
14
|
```
|
15
15
|
|
16
16
|
**Strictness**
|
17
17
|
|
18
18
|
Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches
|
19
|
-
given selector.
|
19
|
+
a given selector.
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
# Throws if there are several frames in DOM:
|
23
|
-
page.frame_locator('.result-frame').
|
23
|
+
page.frame_locator('.result-frame').get_by_role('button').click
|
24
24
|
|
25
25
|
# Works because we explicitly tell locator to pick the first frame:
|
26
|
-
page.frame_locator('.result-frame').first.
|
26
|
+
page.frame_locator('.result-frame').first.get_by_role('button').click
|
27
27
|
```
|
28
28
|
|
29
29
|
**Converting Locator to FrameLocator**
|
@@ -54,6 +54,103 @@ def frame_locator(selector)
|
|
54
54
|
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
|
55
55
|
that iframe.
|
56
56
|
|
57
|
+
## get_by_alt_text
|
58
|
+
|
59
|
+
```
|
60
|
+
def get_by_alt_text(text, exact: nil)
|
61
|
+
```
|
62
|
+
|
63
|
+
Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
64
|
+
|
65
|
+
```html
|
66
|
+
<img alt='Castle'>
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## get_by_label
|
71
|
+
|
72
|
+
```
|
73
|
+
def get_by_label(text, exact: nil)
|
74
|
+
```
|
75
|
+
|
76
|
+
Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
77
|
+
label text Password in the following DOM:
|
78
|
+
|
79
|
+
```html
|
80
|
+
<label for="password-input">Password:</label>
|
81
|
+
<input id="password-input">
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
## get_by_placeholder
|
86
|
+
|
87
|
+
```
|
88
|
+
def get_by_placeholder(text, exact: nil)
|
89
|
+
```
|
90
|
+
|
91
|
+
Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
92
|
+
"Country":
|
93
|
+
|
94
|
+
```html
|
95
|
+
<input placeholder="Country">
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
## get_by_role
|
100
|
+
|
101
|
+
```
|
102
|
+
def get_by_role(
|
103
|
+
role,
|
104
|
+
checked: nil,
|
105
|
+
disabled: nil,
|
106
|
+
expanded: nil,
|
107
|
+
includeHidden: nil,
|
108
|
+
level: nil,
|
109
|
+
name: nil,
|
110
|
+
pressed: nil,
|
111
|
+
selected: nil)
|
112
|
+
```
|
113
|
+
|
114
|
+
Allows locating elements by their [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles),
|
115
|
+
[ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and
|
116
|
+
[accessible name](https://w3c.github.io/accname/#dfn-accessible-name). Note that role selector **does not replace**
|
117
|
+
accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
118
|
+
|
119
|
+
Note that many html elements have an implicitly
|
120
|
+
[defined role](https://w3c.github.io/html-aam/#html-element-role-mappings) that is recognized by the role selector. You
|
121
|
+
can find all the [supported roles here](https://www.w3.org/TR/wai-aria-1.2/#role_definitions). ARIA guidelines **do not
|
122
|
+
recommend** duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values.
|
123
|
+
|
124
|
+
## get_by_test_id
|
125
|
+
|
126
|
+
```
|
127
|
+
def get_by_test_id(testId)
|
128
|
+
```
|
129
|
+
|
130
|
+
Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use
|
131
|
+
[Selectors#set_test_id_attribute](./selectors#set_test_id_attribute) to configure a different test id attribute if necessary.
|
132
|
+
|
133
|
+
## get_by_text
|
134
|
+
|
135
|
+
```
|
136
|
+
def get_by_text(text, exact: nil)
|
137
|
+
```
|
138
|
+
|
139
|
+
Allows locating elements that contain given text.
|
140
|
+
|
141
|
+
## get_by_title
|
142
|
+
|
143
|
+
```
|
144
|
+
def get_by_title(text, exact: nil)
|
145
|
+
```
|
146
|
+
|
147
|
+
Allows locating elements by their title. For example, this method will find the button by its title "Submit":
|
148
|
+
|
149
|
+
```html
|
150
|
+
<button title='Place the order'>Order Now</button>
|
151
|
+
```
|
152
|
+
|
153
|
+
|
57
154
|
## last
|
58
155
|
|
59
156
|
```
|
@@ -68,7 +165,10 @@ Returns locator to the last matching frame.
|
|
68
165
|
def locator(selector, has: nil, hasText: nil)
|
69
166
|
```
|
70
167
|
|
71
|
-
The method finds an element matching the specified selector in the
|
168
|
+
The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
169
|
+
similar to [Locator#filter](./locator#filter) method.
|
170
|
+
|
171
|
+
[Learn more about locators](https://playwright.dev/python/docs/locators).
|
72
172
|
|
73
173
|
## nth
|
74
174
|
|
@@ -190,6 +190,22 @@ def drag_to(
|
|
190
190
|
trial: nil)
|
191
191
|
```
|
192
192
|
|
193
|
+
This method drags the locator to another target locator or target position. It will first move to the source element,
|
194
|
+
perform a `mousedown`, then move to the target element or position and perform a `mouseup`.
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
source = page.locator("#source")
|
198
|
+
target = page.locator("#target")
|
199
|
+
|
200
|
+
source.drag_to(target)
|
201
|
+
# or specify exact positions relative to the top-left corners of the elements:
|
202
|
+
source.drag_to(
|
203
|
+
target,
|
204
|
+
sourcePosition: { x: 34, y: 7 },
|
205
|
+
targetPosition: { x: 10, y: 20 },
|
206
|
+
)
|
207
|
+
```
|
208
|
+
|
193
209
|
|
194
210
|
|
195
211
|
## element_handle
|
@@ -298,8 +314,8 @@ multiple times.
|
|
298
314
|
row_locator = page.locator("tr")
|
299
315
|
# ...
|
300
316
|
row_locator.
|
301
|
-
filter(
|
302
|
-
filter(has
|
317
|
+
filter(hasText: "text in column 1").
|
318
|
+
filter(has: page.get_by_role("button", name: "column 2 button")).
|
303
319
|
screenshot
|
304
320
|
```
|
305
321
|
|
@@ -331,7 +347,7 @@ When working with iframes, you can create a frame locator that will enter the if
|
|
331
347
|
that iframe:
|
332
348
|
|
333
349
|
```ruby
|
334
|
-
locator = page.frame_locator("iframe").
|
350
|
+
locator = page.frame_locator("iframe").get_by_text("Submit")
|
335
351
|
locator.click
|
336
352
|
```
|
337
353
|
|
@@ -346,6 +362,103 @@ alias: `[]`
|
|
346
362
|
|
347
363
|
Returns element attribute value.
|
348
364
|
|
365
|
+
## get_by_alt_text
|
366
|
+
|
367
|
+
```
|
368
|
+
def get_by_alt_text(text, exact: nil)
|
369
|
+
```
|
370
|
+
|
371
|
+
Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
372
|
+
|
373
|
+
```html
|
374
|
+
<img alt='Castle'>
|
375
|
+
```
|
376
|
+
|
377
|
+
|
378
|
+
## get_by_label
|
379
|
+
|
380
|
+
```
|
381
|
+
def get_by_label(text, exact: nil)
|
382
|
+
```
|
383
|
+
|
384
|
+
Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
385
|
+
label text Password in the following DOM:
|
386
|
+
|
387
|
+
```html
|
388
|
+
<label for="password-input">Password:</label>
|
389
|
+
<input id="password-input">
|
390
|
+
```
|
391
|
+
|
392
|
+
|
393
|
+
## get_by_placeholder
|
394
|
+
|
395
|
+
```
|
396
|
+
def get_by_placeholder(text, exact: nil)
|
397
|
+
```
|
398
|
+
|
399
|
+
Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
400
|
+
"Country":
|
401
|
+
|
402
|
+
```html
|
403
|
+
<input placeholder="Country">
|
404
|
+
```
|
405
|
+
|
406
|
+
|
407
|
+
## get_by_role
|
408
|
+
|
409
|
+
```
|
410
|
+
def get_by_role(
|
411
|
+
role,
|
412
|
+
checked: nil,
|
413
|
+
disabled: nil,
|
414
|
+
expanded: nil,
|
415
|
+
includeHidden: nil,
|
416
|
+
level: nil,
|
417
|
+
name: nil,
|
418
|
+
pressed: nil,
|
419
|
+
selected: nil)
|
420
|
+
```
|
421
|
+
|
422
|
+
Allows locating elements by their [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles),
|
423
|
+
[ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and
|
424
|
+
[accessible name](https://w3c.github.io/accname/#dfn-accessible-name). Note that role selector **does not replace**
|
425
|
+
accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
426
|
+
|
427
|
+
Note that many html elements have an implicitly
|
428
|
+
[defined role](https://w3c.github.io/html-aam/#html-element-role-mappings) that is recognized by the role selector. You
|
429
|
+
can find all the [supported roles here](https://www.w3.org/TR/wai-aria-1.2/#role_definitions). ARIA guidelines **do not
|
430
|
+
recommend** duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values.
|
431
|
+
|
432
|
+
## get_by_test_id
|
433
|
+
|
434
|
+
```
|
435
|
+
def get_by_test_id(testId)
|
436
|
+
```
|
437
|
+
|
438
|
+
Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use
|
439
|
+
[Selectors#set_test_id_attribute](./selectors#set_test_id_attribute) to configure a different test id attribute if necessary.
|
440
|
+
|
441
|
+
## get_by_text
|
442
|
+
|
443
|
+
```
|
444
|
+
def get_by_text(text, exact: nil)
|
445
|
+
```
|
446
|
+
|
447
|
+
Allows locating elements that contain given text.
|
448
|
+
|
449
|
+
## get_by_title
|
450
|
+
|
451
|
+
```
|
452
|
+
def get_by_title(text, exact: nil)
|
453
|
+
```
|
454
|
+
|
455
|
+
Allows locating elements by their title. For example, this method will find the button by its title "Submit":
|
456
|
+
|
457
|
+
```html
|
458
|
+
<button title='Place the order'>Order Now</button>
|
459
|
+
```
|
460
|
+
|
461
|
+
|
349
462
|
## highlight
|
350
463
|
|
351
464
|
```
|
@@ -466,9 +579,11 @@ Returns locator to the last matching element.
|
|
466
579
|
def locator(selector, has: nil, hasText: nil)
|
467
580
|
```
|
468
581
|
|
469
|
-
The method finds an element matching the specified selector in the
|
582
|
+
The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
470
583
|
similar to [Locator#filter](./locator#filter) method.
|
471
584
|
|
585
|
+
[Learn more about locators](https://playwright.dev/python/docs/locators).
|
586
|
+
|
472
587
|
## nth
|
473
588
|
|
474
589
|
```
|
@@ -684,8 +799,8 @@ element.type("world", delay: 100) # types slower, like a user
|
|
684
799
|
An example of typing into a text field and then submitting the form:
|
685
800
|
|
686
801
|
```ruby
|
687
|
-
element = page.
|
688
|
-
element.type("
|
802
|
+
element = page.get_by_label("Password")
|
803
|
+
element.type("my password")
|
689
804
|
element.press("Enter")
|
690
805
|
```
|
691
806
|
|