playwright-ruby-client 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/README.md +33 -0
  3. data/documentation/babel.config.js +3 -0
  4. data/documentation/docs/api/accessibility.md +7 -0
  5. data/documentation/docs/api/browser.md +185 -0
  6. data/documentation/docs/api/browser_context.md +398 -0
  7. data/documentation/docs/api/browser_type.md +105 -0
  8. data/documentation/docs/api/cdp_session.md +7 -0
  9. data/documentation/docs/api/console_message.md +41 -0
  10. data/documentation/docs/api/dialog.md +74 -0
  11. data/documentation/docs/api/element_handle.md +640 -0
  12. data/documentation/docs/api/experimental/_category_.yml +3 -0
  13. data/documentation/docs/api/experimental/android.md +25 -0
  14. data/documentation/docs/api/experimental/android_device.md +91 -0
  15. data/documentation/docs/api/experimental/android_input.md +38 -0
  16. data/documentation/docs/api/experimental/android_socket.md +7 -0
  17. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  18. data/documentation/docs/api/file_chooser.md +51 -0
  19. data/documentation/docs/api/frame.md +867 -0
  20. data/documentation/docs/api/js_handle.md +116 -0
  21. data/documentation/docs/api/keyboard.md +157 -0
  22. data/documentation/docs/api/mouse.md +69 -0
  23. data/documentation/docs/api/page.md +1469 -0
  24. data/documentation/docs/api/playwright.md +63 -0
  25. data/documentation/docs/api/request.md +188 -0
  26. data/documentation/docs/api/response.md +97 -0
  27. data/documentation/docs/api/route.md +80 -0
  28. data/documentation/docs/api/selectors.md +23 -0
  29. data/documentation/docs/api/touchscreen.md +8 -0
  30. data/documentation/docs/api/tracing.md +54 -0
  31. data/documentation/docs/api/web_socket.md +7 -0
  32. data/documentation/docs/api/worker.md +7 -0
  33. data/documentation/docs/article/api_coverage.mdx +11 -0
  34. data/documentation/docs/article/getting_started.md +152 -0
  35. data/documentation/docs/article/guides/_category_.yml +3 -0
  36. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  37. data/documentation/docs/article/guides/launch_browser.md +119 -0
  38. data/documentation/docs/article/guides/rails_integration.md +51 -0
  39. data/{docs → documentation/docs/include}/api_coverage.md +0 -0
  40. data/documentation/docusaurus.config.js +107 -0
  41. data/documentation/package.json +39 -0
  42. data/documentation/sidebars.js +15 -0
  43. data/documentation/src/components/HomepageFeatures.js +61 -0
  44. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  45. data/documentation/src/css/custom.css +44 -0
  46. data/documentation/src/pages/index.js +50 -0
  47. data/documentation/src/pages/index.module.css +41 -0
  48. data/documentation/src/pages/markdown-page.md +7 -0
  49. data/documentation/static/.nojekyll +0 -0
  50. data/documentation/static/img/playwright-logo.svg +9 -0
  51. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  52. data/documentation/static/img/undraw_web_development.svg +1 -0
  53. data/documentation/static/img/undraw_windows.svg +1 -0
  54. data/documentation/yarn.lock +8805 -0
  55. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  56. data/lib/playwright/channel_owners/browser_context.rb +2 -2
  57. data/lib/playwright/channel_owners/element_handle.rb +2 -10
  58. data/lib/playwright/channel_owners/frame.rb +6 -28
  59. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  60. data/lib/playwright/channel_owners/page.rb +10 -1
  61. data/lib/playwright/input_files.rb +0 -8
  62. data/lib/playwright/javascript.rb +0 -10
  63. data/lib/playwright/javascript/expression.rb +2 -7
  64. data/lib/playwright/version.rb +1 -1
  65. data/lib/playwright_api/accessibility.rb +7 -89
  66. data/lib/playwright_api/android.rb +7 -64
  67. data/lib/playwright_api/android_device.rb +8 -8
  68. data/lib/playwright_api/browser.rb +15 -169
  69. data/lib/playwright_api/browser_context.rb +47 -609
  70. data/lib/playwright_api/browser_type.rb +13 -103
  71. data/lib/playwright_api/cdp_session.rb +2 -25
  72. data/lib/playwright_api/console_message.rb +6 -6
  73. data/lib/playwright_api/dialog.rb +11 -92
  74. data/lib/playwright_api/element_handle.rb +60 -362
  75. data/lib/playwright_api/file_chooser.rb +0 -28
  76. data/lib/playwright_api/frame.rb +74 -713
  77. data/lib/playwright_api/js_handle.rb +16 -90
  78. data/lib/playwright_api/keyboard.rb +21 -213
  79. data/lib/playwright_api/mouse.rb +1 -45
  80. data/lib/playwright_api/page.rb +155 -1635
  81. data/lib/playwright_api/playwright.rb +14 -117
  82. data/lib/playwright_api/request.rb +15 -121
  83. data/lib/playwright_api/response.rb +9 -9
  84. data/lib/playwright_api/route.rb +8 -105
  85. data/lib/playwright_api/selectors.rb +6 -97
  86. data/lib/playwright_api/tracing.rb +1 -61
  87. data/lib/playwright_api/web_socket.rb +1 -1
  88. data/lib/playwright_api/worker.rb +6 -42
  89. metadata +55 -4
  90. data/lib/playwright/javascript/function.rb +0 -67
@@ -0,0 +1,3 @@
1
+ label: Experimental
2
+ position: 1000
3
+ collapsed: false
@@ -0,0 +1,25 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # Android
6
+
7
+ Playwright has **experimental** support for Android automation. You can access android namespace via:
8
+
9
+ An example of the Android automation script would be:
10
+
11
+ Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
12
+ via setting the following environment variable when installing Playwright:
13
+
14
+ ```sh js
15
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
16
+ ```
17
+
18
+
19
+ ## devices
20
+
21
+ ```
22
+ def devices
23
+ ```
24
+
25
+ Returns the list of detected Android devices.
@@ -0,0 +1,91 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # AndroidDevice
6
+
7
+ [AndroidDevice](./android_device) represents a connected device, either real hardware or emulated. Devices can be obtained using
8
+ [Android#devices](./android#devices).
9
+
10
+ ## close
11
+
12
+ ```
13
+ def close
14
+ ```
15
+
16
+ Disconnects from the device.
17
+
18
+ ## info
19
+
20
+ ```
21
+ def info(selector)
22
+ ```
23
+
24
+ Returns information about a widget defined by `selector`.
25
+
26
+ ## launch_browser
27
+
28
+ ```
29
+ def launch_browser(
30
+ acceptDownloads: nil,
31
+ bypassCSP: nil,
32
+ colorScheme: nil,
33
+ command: nil,
34
+ deviceScaleFactor: nil,
35
+ extraHTTPHeaders: nil,
36
+ geolocation: nil,
37
+ hasTouch: nil,
38
+ httpCredentials: nil,
39
+ ignoreHTTPSErrors: nil,
40
+ isMobile: nil,
41
+ javaScriptEnabled: nil,
42
+ locale: nil,
43
+ noViewport: nil,
44
+ offline: nil,
45
+ permissions: nil,
46
+ record_har_omit_content: nil,
47
+ record_har_path: nil,
48
+ record_video_dir: nil,
49
+ record_video_size: nil,
50
+ screen: nil,
51
+ timezoneId: nil,
52
+ userAgent: nil,
53
+ viewport: nil,
54
+ &block)
55
+ ```
56
+
57
+ Launches Chrome browser on the device, and returns its persistent context.
58
+
59
+ ## model
60
+
61
+ ```
62
+ def model
63
+ ```
64
+
65
+ Device model.
66
+
67
+ ## screenshot
68
+
69
+ ```
70
+ def screenshot(path: nil)
71
+ ```
72
+
73
+ Returns the buffer with the captured screenshot of the device.
74
+
75
+ ## serial
76
+
77
+ ```
78
+ def serial
79
+ ```
80
+
81
+ Device serial number.
82
+
83
+ ## shell
84
+
85
+ ```
86
+ def shell(command)
87
+ ```
88
+
89
+ Executes a shell command on the device and returns its output.
90
+
91
+ ## input
@@ -0,0 +1,38 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # AndroidInput
6
+
7
+
8
+ ## drag
9
+
10
+ ```
11
+ def drag(from, to, steps)
12
+ ```
13
+
14
+ Performs a drag between `from` and `to` points.
15
+
16
+ ## press
17
+
18
+ ```
19
+ def press(key)
20
+ ```
21
+
22
+ Presses the `key`.
23
+
24
+ ## tap_point
25
+
26
+ ```
27
+ def tap_point(point)
28
+ ```
29
+
30
+ Taps at the specified `point`.
31
+
32
+ ## type
33
+
34
+ ```
35
+ def type(text)
36
+ ```
37
+
38
+ Types `text` into currently focused widget.
@@ -0,0 +1,7 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # AndroidSocket
6
+
7
+ Not Implemented
@@ -0,0 +1,7 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # AndroidWebView
6
+
7
+ Not Implemented
@@ -0,0 +1,51 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # FileChooser
6
+
7
+ [FileChooser](./file_chooser) objects are dispatched by the page in the [`event: Page.fileChooser`] event.
8
+
9
+ ```python sync title=example_371975841dd417527a865b1501e3a8ba40f905b895cf3317ca90d9890e980843.py
10
+ with page.expect_file_chooser() as fc_info:
11
+ page.click("upload")
12
+ file_chooser = fc_info.value
13
+ file_chooser.set_files("myfile.pdf")
14
+
15
+ ```
16
+
17
+
18
+
19
+ ## element
20
+
21
+ ```
22
+ def element
23
+ ```
24
+
25
+ Returns input element associated with this file chooser.
26
+
27
+ ## multiple?
28
+
29
+ ```
30
+ def multiple?
31
+ ```
32
+
33
+ Returns whether this file chooser accepts multiple files.
34
+
35
+ ## page
36
+
37
+ ```
38
+ def page
39
+ ```
40
+
41
+ Returns page this file chooser belongs to.
42
+
43
+ ## set_files
44
+
45
+ ```
46
+ def set_files(files, noWaitAfter: nil, timeout: nil)
47
+ ```
48
+ alias: `files=`
49
+
50
+ Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, then
51
+ they are resolved relative to the the current working directory. For empty array, clears the selected files.
@@ -0,0 +1,867 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # Frame
6
+
7
+ At every point of time, page exposes its current frame tree via the [Page#main_frame](./page#main_frame) and
8
+ [Frame#child_frames](./frame#child_frames) methods.
9
+
10
+ [Frame](./frame) object's lifecycle is controlled by three events, dispatched on the page object:
11
+ - [`event: Page.frameAttached`] - fired when the frame gets attached to the page. A Frame can be attached to the page
12
+ only once.
13
+ - [`event: Page.frameNavigated`] - fired when the frame commits navigation to a different URL.
14
+ - [`event: Page.frameDetached`] - fired when the frame gets detached from the page. A Frame can be detached from the
15
+ page only once.
16
+
17
+ An example of dumping frame tree:
18
+
19
+ ```python sync title=example_a4a9e01d1e0879958d591c4bc9061574f5c035e821a94214e650d15564d77bf4.py
20
+ from playwright.sync_api import sync_playwright
21
+
22
+ def run(playwright):
23
+ firefox = playwright.firefox
24
+ browser = firefox.launch()
25
+ page = browser.new_page()
26
+ page.goto("https://www.theverge.com")
27
+ dump_frame_tree(page.main_frame, "")
28
+ browser.close()
29
+
30
+ def dump_frame_tree(frame, indent):
31
+ print(indent + frame.name + '@' + frame.url)
32
+ for child in frame.child_frames:
33
+ dump_frame_tree(child, indent + " ")
34
+
35
+ with sync_playwright() as playwright:
36
+ run(playwright)
37
+
38
+ ```
39
+
40
+
41
+
42
+ ## add_script_tag
43
+
44
+ ```
45
+ def add_script_tag(content: nil, path: nil, type: nil, url: nil)
46
+ ```
47
+
48
+ Returns the added tag when the script's onload fires or when the script content was injected into frame.
49
+
50
+ Adds a `<script>` tag into the page with the desired url or content.
51
+
52
+ ## add_style_tag
53
+
54
+ ```
55
+ def add_style_tag(content: nil, path: nil, url: nil)
56
+ ```
57
+
58
+ Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
59
+
60
+ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
61
+ content.
62
+
63
+ ## check
64
+
65
+ ```
66
+ def check(
67
+ selector,
68
+ force: nil,
69
+ noWaitAfter: nil,
70
+ position: nil,
71
+ timeout: nil,
72
+ trial: nil)
73
+ ```
74
+
75
+ This method checks an element matching `selector` by performing the following steps:
76
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
77
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
78
+ checked, this method returns immediately.
79
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
80
+ element is detached during the checks, the whole action is retried.
81
+ 1. Scroll the element into view if needed.
82
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
83
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
84
+ 1. Ensure that the element is now checked. If not, this method throws.
85
+
86
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
87
+ zero timeout disables this.
88
+
89
+ ## child_frames
90
+
91
+ ```
92
+ def child_frames
93
+ ```
94
+
95
+
96
+
97
+ ## click
98
+
99
+ ```
100
+ def click(
101
+ selector,
102
+ button: nil,
103
+ clickCount: nil,
104
+ delay: nil,
105
+ force: nil,
106
+ modifiers: nil,
107
+ noWaitAfter: nil,
108
+ position: nil,
109
+ timeout: nil,
110
+ trial: nil)
111
+ ```
112
+
113
+ This method clicks an element matching `selector` by performing the following steps:
114
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
115
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
116
+ element is detached during the checks, the whole action is retried.
117
+ 1. Scroll the element into view if needed.
118
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element, or the specified `position`.
119
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
120
+
121
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
122
+ zero timeout disables this.
123
+
124
+ ## content
125
+
126
+ ```
127
+ def content
128
+ ```
129
+
130
+ Gets the full HTML contents of the frame, including the doctype.
131
+
132
+ ## dblclick
133
+
134
+ ```
135
+ def dblclick(
136
+ selector,
137
+ button: nil,
138
+ delay: nil,
139
+ force: nil,
140
+ modifiers: nil,
141
+ noWaitAfter: nil,
142
+ position: nil,
143
+ timeout: nil,
144
+ trial: nil)
145
+ ```
146
+
147
+ This method double clicks an element matching `selector` by performing the following steps:
148
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
149
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
150
+ element is detached during the checks, the whole action is retried.
151
+ 1. Scroll the element into view if needed.
152
+ 1. Use [Page#mouse](./page#mouse) to double click in the center of the element, or the specified `position`.
153
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
154
+ first click of the `dblclick()` triggers a navigation event, this method will throw.
155
+
156
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
157
+ zero timeout disables this.
158
+
159
+ > NOTE: `frame.dblclick()` dispatches two `click` events and a single `dblclick` event.
160
+
161
+ ## dispatch_event
162
+
163
+ ```
164
+ def dispatch_event(selector, type, eventInit: nil, timeout: nil)
165
+ ```
166
+
167
+ The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
168
+ `click` is dispatched. This is equivalent to calling
169
+ [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
170
+
171
+ ```python sync title=example_de439a4f4839a9b1bc72dbe0890d6b989c437620ba1b88a2150faa79f98184fc.py
172
+ frame.dispatch_event("button#submit", "click")
173
+
174
+ ```
175
+
176
+ Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
177
+ and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
178
+
179
+ Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
180
+ - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
181
+ - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
182
+ - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
183
+ - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
184
+ - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
185
+ - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
186
+ - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
187
+
188
+ You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
189
+
190
+ ```python sync title=example_5410f49339561b3cc9d91c7548c8195a570c8be704bb62f45d90c68f869d450d.py
191
+ # note you can only create data_transfer in chromium and firefox
192
+ data_transfer = frame.evaluate_handle("new DataTransfer()")
193
+ frame.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
194
+
195
+ ```
196
+
197
+
198
+
199
+ ## eval_on_selector
200
+
201
+ ```
202
+ def eval_on_selector(selector, expression, arg: nil)
203
+ ```
204
+
205
+ Returns the return value of `expression`.
206
+
207
+ The method finds an element matching the specified selector within the frame and passes it as a first argument to
208
+ `expression`. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, the
209
+ method throws an error.
210
+
211
+ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Frame#eval_on_selector](./frame#eval_on_selector) would wait for the promise to resolve and
212
+ return its value.
213
+
214
+ Examples:
215
+
216
+ ```python sync title=example_6814d0e91763f4d27a0d6a380c36d62b551e4c3e902d1157012dde0a49122abe.py
217
+ search_value = frame.eval_on_selector("#search", "el => el.value")
218
+ preload_href = frame.eval_on_selector("link[rel=preload]", "el => el.href")
219
+ html = frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
220
+
221
+ ```
222
+
223
+
224
+
225
+ ## eval_on_selector_all
226
+
227
+ ```
228
+ def eval_on_selector_all(selector, expression, arg: nil)
229
+ ```
230
+
231
+ Returns the return value of `expression`.
232
+
233
+ The method finds all elements matching the specified selector within the frame and passes an array of matched elements
234
+ as a first argument to `expression`. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more details.
235
+
236
+ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Frame#eval_on_selector_all](./frame#eval_on_selector_all) would wait for the promise to resolve and
237
+ return its value.
238
+
239
+ Examples:
240
+
241
+ ```python sync title=example_618e7f8f681d1c4a1c0c9b8d23892e37cbbef013bf3d8906fd4311c51d9819d7.py
242
+ divs_counts = frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
243
+
244
+ ```
245
+
246
+
247
+
248
+ ## evaluate
249
+
250
+ ```
251
+ def evaluate(expression, arg: nil)
252
+ ```
253
+
254
+ Returns the return value of `expression`.
255
+
256
+ If the function passed to the [Frame#evaluate](./frame#evaluate) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Frame#evaluate](./frame#evaluate) would wait
257
+ for the promise to resolve and return its value.
258
+
259
+ If the function passed to the [Frame#evaluate](./frame#evaluate) returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) value, then
260
+ [Frame#evaluate](./frame#evaluate) returns `undefined`. Playwright also supports transferring some additional values that are
261
+ not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
262
+
263
+ ```python sync title=example_15a235841cd1bc56fad6e3c8aaea2a30e352fedd8238017f22f97fc70e058d2b.py
264
+ result = frame.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
265
+ print(result) # prints "56"
266
+
267
+ ```
268
+
269
+ A string can also be passed in instead of a function.
270
+
271
+ ```python sync title=example_9c73167b900498bca191abc2ce2627e063f84b0abc8ce3a117416cb734602760.py
272
+ print(frame.evaluate("1 + 2")) # prints "3"
273
+ x = 10
274
+ print(frame.evaluate(f"1 + {x}")) # prints "11"
275
+
276
+ ```
277
+
278
+ [ElementHandle](./element_handle) instances can be passed as an argument to the [Frame#evaluate](./frame#evaluate):
279
+
280
+ ```python sync title=example_05568c81173717fa6841099571d8a66e14fc0853e01684630d1622baedc25f67.py
281
+ body_handle = frame.query_selector("body")
282
+ html = frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
283
+ body_handle.dispose()
284
+
285
+ ```
286
+
287
+
288
+
289
+ ## evaluate_handle
290
+
291
+ ```
292
+ def evaluate_handle(expression, arg: nil)
293
+ ```
294
+
295
+ Returns the return value of `expression` as a [JSHandle](./js_handle).
296
+
297
+ The only difference between [Frame#evaluate](./frame#evaluate) and [Frame#evaluate_handle](./frame#evaluate_handle) is that
298
+ [Frame#evaluate_handle](./frame#evaluate_handle) returns [JSHandle](./js_handle).
299
+
300
+ If the function, passed to the [Frame#evaluate_handle](./frame#evaluate_handle), returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then
301
+ [Frame#evaluate_handle](./frame#evaluate_handle) would wait for the promise to resolve and return its value.
302
+
303
+ ```python sync title=example_a1c8e837e826079359d01d6f7eecc64092a45d8c74280d23ee9039c379132c51.py
304
+ a_window_handle = frame.evaluate_handle("Promise.resolve(window)")
305
+ a_window_handle # handle for the window object.
306
+
307
+ ```
308
+
309
+ A string can also be passed in instead of a function.
310
+
311
+ ```python sync title=example_9daa37cfd3d747c9360d9544f64786bf49d291a6887b0efccc813215b62ae4c6.py
312
+ a_handle = page.evaluate_handle("document") # handle for the "document"
313
+
314
+ ```
315
+
316
+ [JSHandle](./js_handle) instances can be passed as an argument to the [Frame#evaluate_handle](./frame#evaluate_handle):
317
+
318
+ ```ruby
319
+ body_handle = page.evaluate_handle("document.body")
320
+ result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
321
+ puts result_handle.json_value()
322
+ result_handle.dispose()
323
+ ```
324
+
325
+
326
+
327
+ ## fill
328
+
329
+ ```
330
+ def fill(selector, value, noWaitAfter: nil, timeout: nil)
331
+ ```
332
+
333
+ This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the
334
+ element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
335
+ field.
336
+
337
+ If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
338
+ However, if the element is inside the `<label>` element that has an associated
339
+ [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
340
+ instead.
341
+
342
+ To send fine-grained keyboard events, use [Frame#type](./frame#type).
343
+
344
+ ## focus
345
+
346
+ ```
347
+ def focus(selector, timeout: nil)
348
+ ```
349
+
350
+ This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
351
+ waits until a matching element appears in the DOM.
352
+
353
+ ## frame_element
354
+
355
+ ```
356
+ def frame_element
357
+ ```
358
+
359
+ Returns the `frame` or `iframe` element handle which corresponds to this frame.
360
+
361
+ This is an inverse of [ElementHandle#content_frame](./element_handle#content_frame). Note that returned handle actually belongs to the parent
362
+ frame.
363
+
364
+ This method throws an error if the frame has been detached before `frameElement()` returns.
365
+
366
+ ```python sync title=example_e6b4fdef29a401d84b17acfa319bee08f39e1f28e07c435463622220c6a24747.py
367
+ frame_element = frame.frame_element()
368
+ content_frame = frame_element.content_frame()
369
+ assert frame == content_frame
370
+
371
+ ```
372
+
373
+
374
+
375
+ ## get_attribute
376
+
377
+ ```
378
+ def get_attribute(selector, name, timeout: nil)
379
+ ```
380
+
381
+ Returns element attribute value.
382
+
383
+ ## goto
384
+
385
+ ```
386
+ def goto(url, referer: nil, timeout: nil, waitUntil: nil)
387
+ ```
388
+
389
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
390
+ last redirect.
391
+
392
+ `frame.goto` will throw an error if:
393
+ - there's an SSL error (e.g. in case of self-signed certificates).
394
+ - target URL is invalid.
395
+ - the `timeout` is exceeded during navigation.
396
+ - the remote server does not respond or is unreachable.
397
+ - the main resource failed to load.
398
+
399
+ `frame.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404
400
+ "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
401
+ [Response#status](./response#status).
402
+
403
+ > NOTE: `frame.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
404
+ `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
405
+ > NOTE: Headless mode doesn't support navigation to a PDF document. See the
406
+ [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
407
+
408
+ ## hover
409
+
410
+ ```
411
+ def hover(
412
+ selector,
413
+ force: nil,
414
+ modifiers: nil,
415
+ position: nil,
416
+ timeout: nil,
417
+ trial: nil)
418
+ ```
419
+
420
+ This method hovers over an element matching `selector` by performing the following steps:
421
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
422
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
423
+ element is detached during the checks, the whole action is retried.
424
+ 1. Scroll the element into view if needed.
425
+ 1. Use [Page#mouse](./page#mouse) to hover over the center of the element, or the specified `position`.
426
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
427
+
428
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
429
+ zero timeout disables this.
430
+
431
+ ## inner_html
432
+
433
+ ```
434
+ def inner_html(selector, timeout: nil)
435
+ ```
436
+
437
+ Returns `element.innerHTML`.
438
+
439
+ ## inner_text
440
+
441
+ ```
442
+ def inner_text(selector, timeout: nil)
443
+ ```
444
+
445
+ Returns `element.innerText`.
446
+
447
+ ## checked?
448
+
449
+ ```
450
+ def checked?(selector, timeout: nil)
451
+ ```
452
+
453
+ Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
454
+
455
+ ## detached?
456
+
457
+ ```
458
+ def detached?
459
+ ```
460
+
461
+ Returns `true` if the frame has been detached, or `false` otherwise.
462
+
463
+ ## disabled?
464
+
465
+ ```
466
+ def disabled?(selector, timeout: nil)
467
+ ```
468
+
469
+ Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
470
+
471
+ ## editable?
472
+
473
+ ```
474
+ def editable?(selector, timeout: nil)
475
+ ```
476
+
477
+ Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
478
+
479
+ ## enabled?
480
+
481
+ ```
482
+ def enabled?(selector, timeout: nil)
483
+ ```
484
+
485
+ Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
486
+
487
+ ## hidden?
488
+
489
+ ```
490
+ def hidden?(selector, timeout: nil)
491
+ ```
492
+
493
+ Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability). `selector` that does not
494
+ match any elements is considered hidden.
495
+
496
+ ## visible?
497
+
498
+ ```
499
+ def visible?(selector, timeout: nil)
500
+ ```
501
+
502
+ Returns whether the element is [visible](https://playwright.dev/python/docs/actionability). `selector` that does not match any elements is
503
+ considered not visible.
504
+
505
+ ## name
506
+
507
+ ```
508
+ def name
509
+ ```
510
+
511
+ Returns frame's name attribute as specified in the tag.
512
+
513
+ If the name is empty, returns the id attribute instead.
514
+
515
+ > NOTE: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
516
+
517
+ ## page
518
+
519
+ ```
520
+ def page
521
+ ```
522
+
523
+ Returns the page containing this frame.
524
+
525
+ ## parent_frame
526
+
527
+ ```
528
+ def parent_frame
529
+ ```
530
+
531
+ Parent frame, if any. Detached frames and main frames return `null`.
532
+
533
+ ## press
534
+
535
+ ```
536
+ def press(
537
+ selector,
538
+ key,
539
+ delay: nil,
540
+ noWaitAfter: nil,
541
+ timeout: nil)
542
+ ```
543
+
544
+ `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
545
+ value or a single character to generate the text for. A superset of the `key` values can be found
546
+ [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
547
+
548
+ `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
549
+ `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
550
+
551
+ Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
552
+
553
+ Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
554
+
555
+ If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
556
+ texts.
557
+
558
+ Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
559
+ modifier, modifier is pressed and being held while the subsequent key is being pressed.
560
+
561
+ ## query_selector
562
+
563
+ ```
564
+ def query_selector(selector)
565
+ ```
566
+
567
+ Returns the ElementHandle pointing to the frame element.
568
+
569
+ The method finds an element matching the specified selector within the frame. See
570
+ [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns `null`.
571
+
572
+ ## query_selector_all
573
+
574
+ ```
575
+ def query_selector_all(selector)
576
+ ```
577
+
578
+ Returns the ElementHandles pointing to the frame elements.
579
+
580
+ The method finds all elements matching the specified selector within the frame. See
581
+ [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns empty array.
582
+
583
+ ## select_option
584
+
585
+ ```
586
+ def select_option(
587
+ selector,
588
+ element: nil,
589
+ index: nil,
590
+ value: nil,
591
+ label: nil,
592
+ noWaitAfter: nil,
593
+ timeout: nil)
594
+ ```
595
+
596
+ This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, waits until
597
+ all specified options are present in the `<select>` element and selects these options.
598
+
599
+ If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
600
+ `<label>` element that has an associated
601
+ [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
602
+
603
+ Returns the array of option values that have been successfully selected.
604
+
605
+ Triggers a `change` and `input` event once all the provided options have been selected.
606
+
607
+ ```python sync title=example_230c12044664b222bf35d6163b1e415c011d87d9911a4d39648c7f601b344a31.py
608
+ # single selection matching the value
609
+ frame.select_option("select#colors", "blue")
610
+ # single selection matching both the label
611
+ frame.select_option("select#colors", label="blue")
612
+ # multiple selection
613
+ frame.select_option("select#colors", value=["red", "green", "blue"])
614
+
615
+ ```
616
+
617
+
618
+
619
+ ## set_content
620
+
621
+ ```
622
+ def set_content(html, timeout: nil, waitUntil: nil)
623
+ ```
624
+ alias: `content=`
625
+
626
+
627
+
628
+ ## set_input_files
629
+
630
+ ```
631
+ def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
632
+ ```
633
+
634
+ This method expects `selector` to point to an
635
+ [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
636
+
637
+ Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
638
+ are resolved relative to the the current working directory. For empty array, clears the selected files.
639
+
640
+ ## tap_point
641
+
642
+ ```
643
+ def tap_point(
644
+ selector,
645
+ force: nil,
646
+ modifiers: nil,
647
+ noWaitAfter: nil,
648
+ position: nil,
649
+ timeout: nil,
650
+ trial: nil)
651
+ ```
652
+
653
+ This method taps an element matching `selector` by performing the following steps:
654
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
655
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
656
+ element is detached during the checks, the whole action is retried.
657
+ 1. Scroll the element into view if needed.
658
+ 1. Use [Page#touchscreen](./page#touchscreen) to tap the center of the element, or the specified `position`.
659
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
660
+
661
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
662
+ zero timeout disables this.
663
+
664
+ > NOTE: `frame.tap()` requires that the `hasTouch` option of the browser context be set to true.
665
+
666
+ ## text_content
667
+
668
+ ```
669
+ def text_content(selector, timeout: nil)
670
+ ```
671
+
672
+ Returns `element.textContent`.
673
+
674
+ ## title
675
+
676
+ ```
677
+ def title
678
+ ```
679
+
680
+ Returns the page title.
681
+
682
+ ## type
683
+
684
+ ```
685
+ def type(
686
+ selector,
687
+ text,
688
+ delay: nil,
689
+ noWaitAfter: nil,
690
+ timeout: nil)
691
+ ```
692
+
693
+ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used to
694
+ send fine-grained keyboard events. To fill values in form fields, use [Frame#fill](./frame#fill).
695
+
696
+ To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
697
+
698
+ ```python sync title=example_beae7f0d11663c3c98b9d3a8e6ab76b762578cf2856e3b04ad8e42bfb23bb1e1.py
699
+ frame.type("#mytextarea", "hello") # types instantly
700
+ frame.type("#mytextarea", "world", delay=100) # types slower, like a user
701
+
702
+ ```
703
+
704
+
705
+
706
+ ## uncheck
707
+
708
+ ```
709
+ def uncheck(
710
+ selector,
711
+ force: nil,
712
+ noWaitAfter: nil,
713
+ position: nil,
714
+ timeout: nil,
715
+ trial: nil)
716
+ ```
717
+
718
+ This method checks an element matching `selector` by performing the following steps:
719
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
720
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
721
+ unchecked, this method returns immediately.
722
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
723
+ element is detached during the checks, the whole action is retried.
724
+ 1. Scroll the element into view if needed.
725
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
726
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
727
+ 1. Ensure that the element is now unchecked. If not, this method throws.
728
+
729
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
730
+ zero timeout disables this.
731
+
732
+ ## url
733
+
734
+ ```
735
+ def url
736
+ ```
737
+
738
+ Returns frame's url.
739
+
740
+ ## wait_for_function
741
+
742
+ ```
743
+ def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
744
+ ```
745
+
746
+ Returns when the `expression` returns a truthy value, returns that value.
747
+
748
+ The [Frame#wait_for_function](./frame#wait_for_function) can be used to observe viewport size change:
749
+
750
+ ```python sync title=example_2f82dcf15fa9338be87a4faf7fe7de3c542040924db1e1ad1c98468ec0f425ce.py
751
+ from playwright.sync_api import sync_playwright
752
+
753
+ def run(playwright):
754
+ webkit = playwright.webkit
755
+ browser = webkit.launch()
756
+ page = browser.new_page()
757
+ page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
758
+ page.main_frame.wait_for_function("() => window.x > 0")
759
+ browser.close()
760
+
761
+ with sync_playwright() as playwright:
762
+ run(playwright)
763
+
764
+ ```
765
+
766
+ To pass an argument to the predicate of `frame.waitForFunction` function:
767
+
768
+ ```python sync title=example_8b95be0fb4d149890f7817d9473428a50dc631d3a75baf89846648ca6a157562.py
769
+ selector = ".foo"
770
+ frame.wait_for_function("selector => !!document.querySelector(selector)", selector)
771
+
772
+ ```
773
+
774
+
775
+
776
+ ## wait_for_load_state
777
+
778
+ ```
779
+ def wait_for_load_state(state: nil, timeout: nil)
780
+ ```
781
+
782
+ Waits for the required load state to be reached.
783
+
784
+ This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed
785
+ when this method is called. If current document has already reached the required state, resolves immediately.
786
+
787
+ ```python sync title=example_fe41b79b58d046cda4673ededd4d216cb97a63204fcba69375ce8a84ea3f6894.py
788
+ frame.click("button") # click triggers navigation.
789
+ frame.wait_for_load_state() # the promise resolves after "load" event.
790
+
791
+ ```
792
+
793
+
794
+
795
+ ## expect_navigation
796
+
797
+ ```
798
+ def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
799
+ ```
800
+
801
+ Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
802
+ will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
803
+ History API usage, the navigation will resolve with `null`.
804
+
805
+ This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause
806
+ the frame to navigate. Consider this example:
807
+
808
+ ```python sync title=example_03f0ac17eb6c1ce8780cfa83c4ae15a9ddbfde3f96c96f36fdf3fbf9aac721f7.py
809
+ with frame.expect_navigation():
810
+ frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
811
+ # Resolves after navigation has finished
812
+
813
+ ```
814
+
815
+ > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
816
+ considered a navigation.
817
+
818
+ ## wait_for_selector
819
+
820
+ ```
821
+ def wait_for_selector(selector, state: nil, timeout: nil)
822
+ ```
823
+
824
+ Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
825
+ `detached`.
826
+
827
+ Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
828
+ the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
829
+ selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
830
+
831
+ This method works across navigations:
832
+
833
+ ```python sync title=example_a5b9dd4745d45ac630e5953be1c1815ae8e8ab03399fb35f45ea77c434f17eea.py
834
+ from playwright.sync_api import sync_playwright
835
+
836
+ def run(playwright):
837
+ chromium = playwright.chromium
838
+ browser = chromium.launch()
839
+ page = browser.new_page()
840
+ for current_url in ["https://google.com", "https://bbc.com"]:
841
+ page.goto(current_url, wait_until="domcontentloaded")
842
+ element = page.main_frame.wait_for_selector("img")
843
+ print("Loaded image: " + str(element.get_attribute("src")))
844
+ browser.close()
845
+
846
+ with sync_playwright() as playwright:
847
+ run(playwright)
848
+
849
+ ```
850
+
851
+
852
+
853
+ ## wait_for_url
854
+
855
+ ```
856
+ def wait_for_url(url, timeout: nil, waitUntil: nil)
857
+ ```
858
+
859
+ Waits for the frame to navigate to the given URL.
860
+
861
+ ```python sync title=example_86a9a19ec4c41e1a5ac302fbca9a3d3d6dca3fe3314e065b8062ddf5f75abfbd.py
862
+ frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
863
+ frame.wait_for_url("**/target.html")
864
+
865
+ ```
866
+
867
+