playwright-ruby-client 0.7.1 → 1.14.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -0
  3. data/documentation/docs/api/accessibility.md +52 -1
  4. data/documentation/docs/api/browser.md +8 -2
  5. data/documentation/docs/api/browser_context.md +28 -0
  6. data/documentation/docs/api/browser_type.md +1 -0
  7. data/documentation/docs/api/download.md +97 -0
  8. data/documentation/docs/api/element_handle.md +38 -4
  9. data/documentation/docs/api/experimental/android_device.md +1 -0
  10. data/documentation/docs/api/frame.md +89 -17
  11. data/documentation/docs/api/keyboard.md +11 -20
  12. data/documentation/docs/api/locator.md +650 -0
  13. data/documentation/docs/api/page.md +135 -19
  14. data/documentation/docs/api/response.md +16 -0
  15. data/documentation/docs/api/touchscreen.md +8 -0
  16. data/documentation/docs/api/worker.md +37 -0
  17. data/documentation/docs/article/guides/inspector.md +31 -0
  18. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +91 -0
  19. data/documentation/docs/article/guides/semi_automation.md +5 -1
  20. data/documentation/docs/include/api_coverage.md +77 -14
  21. data/lib/playwright.rb +36 -4
  22. data/lib/playwright/accessibility_impl.rb +50 -0
  23. data/lib/playwright/channel_owners/artifact.rb +4 -0
  24. data/lib/playwright/channel_owners/browser_context.rb +77 -3
  25. data/lib/playwright/channel_owners/element_handle.rb +11 -4
  26. data/lib/playwright/channel_owners/frame.rb +107 -34
  27. data/lib/playwright/channel_owners/page.rb +163 -55
  28. data/lib/playwright/channel_owners/response.rb +8 -0
  29. data/lib/playwright/channel_owners/worker.rb +23 -0
  30. data/lib/playwright/connection.rb +2 -4
  31. data/lib/playwright/{download.rb → download_impl.rb} +5 -1
  32. data/lib/playwright/javascript/expression.rb +5 -4
  33. data/lib/playwright/locator_impl.rb +314 -0
  34. data/lib/playwright/route_handler_entry.rb +3 -2
  35. data/lib/playwright/timeout_settings.rb +4 -4
  36. data/lib/playwright/touchscreen_impl.rb +7 -0
  37. data/lib/playwright/transport.rb +0 -1
  38. data/lib/playwright/url_matcher.rb +12 -2
  39. data/lib/playwright/version.rb +2 -2
  40. data/lib/playwright/web_socket_client.rb +164 -0
  41. data/lib/playwright/web_socket_transport.rb +104 -0
  42. data/lib/playwright_api/accessibility.rb +1 -1
  43. data/lib/playwright_api/android_device.rb +6 -5
  44. data/lib/playwright_api/browser.rb +10 -4
  45. data/lib/playwright_api/browser_context.rb +12 -7
  46. data/lib/playwright_api/browser_type.rb +2 -1
  47. data/lib/playwright_api/cdp_session.rb +6 -6
  48. data/lib/playwright_api/download.rb +70 -0
  49. data/lib/playwright_api/element_handle.rb +38 -18
  50. data/lib/playwright_api/frame.rb +95 -44
  51. data/lib/playwright_api/locator.rb +509 -0
  52. data/lib/playwright_api/page.rb +102 -49
  53. data/lib/playwright_api/response.rb +10 -0
  54. data/lib/playwright_api/touchscreen.rb +1 -1
  55. data/lib/playwright_api/worker.rb +13 -3
  56. metadata +17 -7
@@ -12,35 +12,31 @@ to manually fire events as if they were generated from a real keyboard.
12
12
 
13
13
  An example of holding down `Shift` in order to select and delete some text:
14
14
 
15
- ```python sync title=example_575870a45e4fe08d3e06be3420e8a11be03f85791cd8174f27198c016031ae72.py
15
+ ```ruby
16
16
  page.keyboard.type("Hello World!")
17
17
  page.keyboard.press("ArrowLeft")
18
18
  page.keyboard.down("Shift")
19
- for i in range(6):
20
- page.keyboard.press("ArrowLeft")
19
+ 6.times { page.keyboard.press("ArrowLeft") }
21
20
  page.keyboard.up("Shift")
22
21
  page.keyboard.press("Backspace")
23
22
  # result text will end up saying "Hello!"
24
-
25
23
  ```
26
24
 
27
25
  An example of pressing uppercase `A`
28
26
 
29
- ```python sync title=example_a4f00f0cd486431b7eca785304f4e9715522da45b66dda7f3a5f6899b889b9fd.py
27
+ ```ruby
30
28
  page.keyboard.press("Shift+KeyA")
31
29
  # or
32
30
  page.keyboard.press("Shift+A")
33
-
34
31
  ```
35
32
 
36
33
  An example to trigger select-all with the keyboard
37
34
 
38
- ```python sync title=example_2deda0786a20a28cec9e8b438078a5fc567f7c7e5cf369419ab3c4d80a319ff6.py
35
+ ```ruby
39
36
  # on windows and linux
40
37
  page.keyboard.press("Control+A")
41
38
  # on mac_os
42
39
  page.keyboard.press("Meta+A")
43
-
44
40
  ```
45
41
 
46
42
 
@@ -84,9 +80,8 @@ def insert_text(text)
84
80
 
85
81
  Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.
86
82
 
87
- ```python sync title=example_a9cc2667e9f3e3b8c619649d7e4a7f5db9463e0b76d67a5e588158093a9e9124.py
83
+ ```ruby
88
84
  page.keyboard.insert_text("嗨")
89
-
90
85
  ```
91
86
 
92
87
  > NOTE: Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
@@ -114,17 +109,14 @@ texts.
114
109
  Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
115
110
  modifier, modifier is pressed and being held while the subsequent key is being pressed.
116
111
 
117
- ```python sync title=example_88943eb85c1ac7c261601e6edbdead07a31c2784326c496e10667ede1a853bab.py
118
- page = browser.new_page()
112
+ ```ruby
119
113
  page.goto("https://keycode.info")
120
114
  page.keyboard.press("a")
121
- page.screenshot(path="a.png")
115
+ page.screenshot(path: "a.png")
122
116
  page.keyboard.press("ArrowLeft")
123
- page.screenshot(path="arrow_left.png")
117
+ page.screenshot(path: "arrow_left.png")
124
118
  page.keyboard.press("Shift+O")
125
- page.screenshot(path="o.png")
126
- browser.close()
127
-
119
+ page.screenshot(path: "o.png")
128
120
  ```
129
121
 
130
122
  Shortcut for [Keyboard#down](./keyboard#down) and [Keyboard#up](./keyboard#up).
@@ -139,10 +131,9 @@ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in t
139
131
 
140
132
  To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
141
133
 
142
- ```python sync title=example_d9ced919f139961fd2b795c71375ca96f788a19c1f8e1479c5ec905fb5c02d43.py
134
+ ```ruby
143
135
  page.keyboard.type("Hello") # types instantly
144
- page.keyboard.type("World", delay=100) # types slower, like a user
145
-
136
+ page.keyboard.type("World", delay: 100) # types slower, like a user
146
137
  ```
147
138
 
148
139
  > NOTE: Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
@@ -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.