playwright-ruby-client 0.5.9 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/documentation/README.md +33 -0
  4. data/documentation/babel.config.js +3 -0
  5. data/documentation/docs/api/accessibility.md +7 -0
  6. data/documentation/docs/api/browser.md +187 -0
  7. data/documentation/docs/api/browser_context.md +397 -0
  8. data/documentation/docs/api/browser_type.md +105 -0
  9. data/documentation/docs/api/cdp_session.md +7 -0
  10. data/documentation/docs/api/console_message.md +41 -0
  11. data/documentation/docs/api/dialog.md +71 -0
  12. data/documentation/docs/api/element_handle.md +618 -0
  13. data/documentation/docs/api/experimental/_category_.yml +3 -0
  14. data/documentation/docs/api/experimental/android.md +25 -0
  15. data/documentation/docs/api/experimental/android_device.md +92 -0
  16. data/documentation/docs/api/experimental/android_input.md +38 -0
  17. data/documentation/docs/api/experimental/android_socket.md +7 -0
  18. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  19. data/documentation/docs/api/file_chooser.md +50 -0
  20. data/documentation/docs/api/frame.md +866 -0
  21. data/documentation/docs/api/js_handle.md +113 -0
  22. data/documentation/docs/api/keyboard.md +157 -0
  23. data/documentation/docs/api/mouse.md +69 -0
  24. data/documentation/docs/api/page.md +1402 -0
  25. data/documentation/docs/api/playwright.md +63 -0
  26. data/documentation/docs/api/request.md +188 -0
  27. data/documentation/docs/api/response.md +97 -0
  28. data/documentation/docs/api/route.md +80 -0
  29. data/documentation/docs/api/selectors.md +23 -0
  30. data/documentation/docs/api/touchscreen.md +8 -0
  31. data/documentation/docs/api/tracing.md +54 -0
  32. data/documentation/docs/api/web_socket.md +7 -0
  33. data/documentation/docs/api/worker.md +24 -0
  34. data/documentation/docs/article/api_coverage.mdx +11 -0
  35. data/documentation/docs/article/getting_started.md +152 -0
  36. data/documentation/docs/article/guides/_category_.yml +3 -0
  37. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  38. data/documentation/docs/article/guides/launch_browser.md +119 -0
  39. data/documentation/docs/article/guides/rails_integration.md +162 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +12 -1
  41. data/documentation/docusaurus.config.js +107 -0
  42. data/documentation/package.json +39 -0
  43. data/documentation/sidebars.js +15 -0
  44. data/documentation/src/components/HomepageFeatures.js +61 -0
  45. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  46. data/documentation/src/css/custom.css +44 -0
  47. data/documentation/src/pages/index.js +50 -0
  48. data/documentation/src/pages/index.module.css +41 -0
  49. data/documentation/src/pages/markdown-page.md +7 -0
  50. data/documentation/static/.nojekyll +0 -0
  51. data/documentation/static/img/playwright-logo.svg +9 -0
  52. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  53. data/documentation/static/img/undraw_web_development.svg +1 -0
  54. data/documentation/static/img/undraw_windows.svg +1 -0
  55. data/documentation/yarn.lock +8805 -0
  56. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  57. data/lib/playwright/channel_owners/browser.rb +11 -2
  58. data/lib/playwright/channel_owners/browser_context.rb +58 -6
  59. data/lib/playwright/channel_owners/browser_type.rb +8 -1
  60. data/lib/playwright/channel_owners/element_handle.rb +17 -16
  61. data/lib/playwright/channel_owners/frame.rb +24 -34
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +37 -52
  64. data/lib/playwright/channel_owners/worker.rb +4 -0
  65. data/lib/playwright/download.rb +3 -2
  66. data/lib/playwright/events.rb +4 -0
  67. data/lib/playwright/input_files.rb +0 -8
  68. data/lib/playwright/javascript.rb +0 -10
  69. data/lib/playwright/javascript/expression.rb +2 -7
  70. data/lib/playwright/playwright_api.rb +16 -1
  71. data/lib/playwright/tracing_impl.rb +31 -0
  72. data/lib/playwright/version.rb +2 -1
  73. data/lib/playwright_api/accessibility.rb +7 -88
  74. data/lib/playwright_api/android.rb +2 -59
  75. data/lib/playwright_api/android_device.rb +6 -5
  76. data/lib/playwright_api/browser.rb +13 -122
  77. data/lib/playwright_api/browser_context.rb +66 -433
  78. data/lib/playwright_api/browser_type.rb +28 -78
  79. data/lib/playwright_api/cdp_session.rb +2 -25
  80. data/lib/playwright_api/console_message.rb +2 -0
  81. data/lib/playwright_api/dialog.rb +5 -63
  82. data/lib/playwright_api/element_handle.rb +96 -294
  83. data/lib/playwright_api/file_chooser.rb +0 -21
  84. data/lib/playwright_api/frame.rb +98 -564
  85. data/lib/playwright_api/js_handle.rb +10 -67
  86. data/lib/playwright_api/keyboard.rb +22 -166
  87. data/lib/playwright_api/mouse.rb +1 -45
  88. data/lib/playwright_api/page.rb +223 -1224
  89. data/lib/playwright_api/playwright.rb +8 -93
  90. data/lib/playwright_api/request.rb +9 -87
  91. data/lib/playwright_api/response.rb +1 -1
  92. data/lib/playwright_api/route.rb +3 -80
  93. data/lib/playwright_api/selectors.rb +0 -66
  94. data/lib/playwright_api/tracing.rb +39 -0
  95. data/lib/playwright_api/web_socket.rb +1 -1
  96. data/lib/playwright_api/worker.rb +28 -42
  97. data/playwright.gemspec +2 -2
  98. metadata +60 -20
  99. 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,92 @@
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
+ reducedMotion: nil,
51
+ screen: nil,
52
+ timezoneId: nil,
53
+ userAgent: nil,
54
+ viewport: nil,
55
+ &block)
56
+ ```
57
+
58
+ Launches Chrome browser on the device, and returns its persistent context.
59
+
60
+ ## model
61
+
62
+ ```
63
+ def model
64
+ ```
65
+
66
+ Device model.
67
+
68
+ ## screenshot
69
+
70
+ ```
71
+ def screenshot(path: nil)
72
+ ```
73
+
74
+ Returns the buffer with the captured screenshot of the device.
75
+
76
+ ## serial
77
+
78
+ ```
79
+ def serial
80
+ ```
81
+
82
+ Device serial number.
83
+
84
+ ## shell
85
+
86
+ ```
87
+ def shell(command)
88
+ ```
89
+
90
+ Executes a shell command on the device and returns its output.
91
+
92
+ ## 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,50 @@
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
+ ```ruby
10
+ file_chooser = page.expect_file_chooser do
11
+ page.click("upload") # action to trigger file uploading
12
+ end
13
+ file_chooser.set_files("myfile.pdf")
14
+ ```
15
+
16
+
17
+
18
+ ## element
19
+
20
+ ```
21
+ def element
22
+ ```
23
+
24
+ Returns input element associated with this file chooser.
25
+
26
+ ## multiple?
27
+
28
+ ```
29
+ def multiple?
30
+ ```
31
+
32
+ Returns whether this file chooser accepts multiple files.
33
+
34
+ ## page
35
+
36
+ ```
37
+ def page
38
+ ```
39
+
40
+ Returns page this file chooser belongs to.
41
+
42
+ ## set_files
43
+
44
+ ```
45
+ def set_files(files, noWaitAfter: nil, timeout: nil)
46
+ ```
47
+ alias: `files=`
48
+
49
+ Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, then
50
+ they are resolved relative to the the current working directory. For empty array, clears the selected files.
@@ -0,0 +1,866 @@
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
+ ```ruby
312
+ a_handle = page.evaluate_handle("document") # handle for the "document"
313
+ ```
314
+
315
+ [JSHandle](./js_handle) instances can be passed as an argument to the [Frame#evaluate_handle](./frame#evaluate_handle):
316
+
317
+ ```ruby
318
+ body_handle = page.evaluate_handle("document.body")
319
+ result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
320
+ puts result_handle.json_value
321
+ result_handle.dispose
322
+ ```
323
+
324
+
325
+
326
+ ## fill
327
+
328
+ ```
329
+ def fill(selector, value, noWaitAfter: nil, timeout: nil)
330
+ ```
331
+
332
+ This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the
333
+ element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
334
+ field.
335
+
336
+ If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
337
+ However, if the element is inside the `<label>` element that has an associated
338
+ [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
339
+ instead.
340
+
341
+ To send fine-grained keyboard events, use [Frame#type](./frame#type).
342
+
343
+ ## focus
344
+
345
+ ```
346
+ def focus(selector, timeout: nil)
347
+ ```
348
+
349
+ This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
350
+ waits until a matching element appears in the DOM.
351
+
352
+ ## frame_element
353
+
354
+ ```
355
+ def frame_element
356
+ ```
357
+
358
+ Returns the `frame` or `iframe` element handle which corresponds to this frame.
359
+
360
+ This is an inverse of [ElementHandle#content_frame](./element_handle#content_frame). Note that returned handle actually belongs to the parent
361
+ frame.
362
+
363
+ This method throws an error if the frame has been detached before `frameElement()` returns.
364
+
365
+ ```python sync title=example_e6b4fdef29a401d84b17acfa319bee08f39e1f28e07c435463622220c6a24747.py
366
+ frame_element = frame.frame_element()
367
+ content_frame = frame_element.content_frame()
368
+ assert frame == content_frame
369
+
370
+ ```
371
+
372
+
373
+
374
+ ## get_attribute
375
+
376
+ ```
377
+ def get_attribute(selector, name, timeout: nil)
378
+ ```
379
+
380
+ Returns element attribute value.
381
+
382
+ ## goto
383
+
384
+ ```
385
+ def goto(url, referer: nil, timeout: nil, waitUntil: nil)
386
+ ```
387
+
388
+ Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
389
+ last redirect.
390
+
391
+ `frame.goto` will throw an error if:
392
+ - there's an SSL error (e.g. in case of self-signed certificates).
393
+ - target URL is invalid.
394
+ - the `timeout` is exceeded during navigation.
395
+ - the remote server does not respond or is unreachable.
396
+ - the main resource failed to load.
397
+
398
+ `frame.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404
399
+ "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
400
+ [Response#status](./response#status).
401
+
402
+ > NOTE: `frame.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
403
+ `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
404
+ > NOTE: Headless mode doesn't support navigation to a PDF document. See the
405
+ [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
406
+
407
+ ## hover
408
+
409
+ ```
410
+ def hover(
411
+ selector,
412
+ force: nil,
413
+ modifiers: nil,
414
+ position: nil,
415
+ timeout: nil,
416
+ trial: nil)
417
+ ```
418
+
419
+ This method hovers over an element matching `selector` by performing the following steps:
420
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
421
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
422
+ element is detached during the checks, the whole action is retried.
423
+ 1. Scroll the element into view if needed.
424
+ 1. Use [Page#mouse](./page#mouse) to hover over the center of the element, or the specified `position`.
425
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
426
+
427
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
428
+ zero timeout disables this.
429
+
430
+ ## inner_html
431
+
432
+ ```
433
+ def inner_html(selector, timeout: nil)
434
+ ```
435
+
436
+ Returns `element.innerHTML`.
437
+
438
+ ## inner_text
439
+
440
+ ```
441
+ def inner_text(selector, timeout: nil)
442
+ ```
443
+
444
+ Returns `element.innerText`.
445
+
446
+ ## checked?
447
+
448
+ ```
449
+ def checked?(selector, timeout: nil)
450
+ ```
451
+
452
+ Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
453
+
454
+ ## detached?
455
+
456
+ ```
457
+ def detached?
458
+ ```
459
+
460
+ Returns `true` if the frame has been detached, or `false` otherwise.
461
+
462
+ ## disabled?
463
+
464
+ ```
465
+ def disabled?(selector, timeout: nil)
466
+ ```
467
+
468
+ Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
469
+
470
+ ## editable?
471
+
472
+ ```
473
+ def editable?(selector, timeout: nil)
474
+ ```
475
+
476
+ Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
477
+
478
+ ## enabled?
479
+
480
+ ```
481
+ def enabled?(selector, timeout: nil)
482
+ ```
483
+
484
+ Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
485
+
486
+ ## hidden?
487
+
488
+ ```
489
+ def hidden?(selector, timeout: nil)
490
+ ```
491
+
492
+ Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability). `selector` that does not
493
+ match any elements is considered hidden.
494
+
495
+ ## visible?
496
+
497
+ ```
498
+ def visible?(selector, timeout: nil)
499
+ ```
500
+
501
+ Returns whether the element is [visible](https://playwright.dev/python/docs/actionability). `selector` that does not match any elements is
502
+ considered not visible.
503
+
504
+ ## name
505
+
506
+ ```
507
+ def name
508
+ ```
509
+
510
+ Returns frame's name attribute as specified in the tag.
511
+
512
+ If the name is empty, returns the id attribute instead.
513
+
514
+ > NOTE: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
515
+
516
+ ## page
517
+
518
+ ```
519
+ def page
520
+ ```
521
+
522
+ Returns the page containing this frame.
523
+
524
+ ## parent_frame
525
+
526
+ ```
527
+ def parent_frame
528
+ ```
529
+
530
+ Parent frame, if any. Detached frames and main frames return `null`.
531
+
532
+ ## press
533
+
534
+ ```
535
+ def press(
536
+ selector,
537
+ key,
538
+ delay: nil,
539
+ noWaitAfter: nil,
540
+ timeout: nil)
541
+ ```
542
+
543
+ `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
544
+ value or a single character to generate the text for. A superset of the `key` values can be found
545
+ [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
546
+
547
+ `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
548
+ `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
549
+
550
+ Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
551
+
552
+ Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
553
+
554
+ If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
555
+ texts.
556
+
557
+ Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
558
+ modifier, modifier is pressed and being held while the subsequent key is being pressed.
559
+
560
+ ## query_selector
561
+
562
+ ```
563
+ def query_selector(selector)
564
+ ```
565
+
566
+ Returns the ElementHandle pointing to the frame element.
567
+
568
+ The method finds an element matching the specified selector within the frame. See
569
+ [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns `null`.
570
+
571
+ ## query_selector_all
572
+
573
+ ```
574
+ def query_selector_all(selector)
575
+ ```
576
+
577
+ Returns the ElementHandles pointing to the frame elements.
578
+
579
+ The method finds all elements matching the specified selector within the frame. See
580
+ [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns empty array.
581
+
582
+ ## select_option
583
+
584
+ ```
585
+ def select_option(
586
+ selector,
587
+ element: nil,
588
+ index: nil,
589
+ value: nil,
590
+ label: nil,
591
+ noWaitAfter: nil,
592
+ timeout: nil)
593
+ ```
594
+
595
+ This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/python/docs/actionability) checks, waits until
596
+ all specified options are present in the `<select>` element and selects these options.
597
+
598
+ If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
599
+ `<label>` element that has an associated
600
+ [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
601
+
602
+ Returns the array of option values that have been successfully selected.
603
+
604
+ Triggers a `change` and `input` event once all the provided options have been selected.
605
+
606
+ ```python sync title=example_230c12044664b222bf35d6163b1e415c011d87d9911a4d39648c7f601b344a31.py
607
+ # single selection matching the value
608
+ frame.select_option("select#colors", "blue")
609
+ # single selection matching both the label
610
+ frame.select_option("select#colors", label="blue")
611
+ # multiple selection
612
+ frame.select_option("select#colors", value=["red", "green", "blue"])
613
+
614
+ ```
615
+
616
+
617
+
618
+ ## set_content
619
+
620
+ ```
621
+ def set_content(html, timeout: nil, waitUntil: nil)
622
+ ```
623
+ alias: `content=`
624
+
625
+
626
+
627
+ ## set_input_files
628
+
629
+ ```
630
+ def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
631
+ ```
632
+
633
+ This method expects `selector` to point to an
634
+ [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
635
+
636
+ Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
637
+ are resolved relative to the the current working directory. For empty array, clears the selected files.
638
+
639
+ ## tap_point
640
+
641
+ ```
642
+ def tap_point(
643
+ selector,
644
+ force: nil,
645
+ modifiers: nil,
646
+ noWaitAfter: nil,
647
+ position: nil,
648
+ timeout: nil,
649
+ trial: nil)
650
+ ```
651
+
652
+ This method taps an element matching `selector` by performing the following steps:
653
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
654
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
655
+ element is detached during the checks, the whole action is retried.
656
+ 1. Scroll the element into view if needed.
657
+ 1. Use [Page#touchscreen](./page#touchscreen) to tap the center of the element, or the specified `position`.
658
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
659
+
660
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
661
+ zero timeout disables this.
662
+
663
+ > NOTE: `frame.tap()` requires that the `hasTouch` option of the browser context be set to true.
664
+
665
+ ## text_content
666
+
667
+ ```
668
+ def text_content(selector, timeout: nil)
669
+ ```
670
+
671
+ Returns `element.textContent`.
672
+
673
+ ## title
674
+
675
+ ```
676
+ def title
677
+ ```
678
+
679
+ Returns the page title.
680
+
681
+ ## type
682
+
683
+ ```
684
+ def type(
685
+ selector,
686
+ text,
687
+ delay: nil,
688
+ noWaitAfter: nil,
689
+ timeout: nil)
690
+ ```
691
+
692
+ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used to
693
+ send fine-grained keyboard events. To fill values in form fields, use [Frame#fill](./frame#fill).
694
+
695
+ To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
696
+
697
+ ```python sync title=example_beae7f0d11663c3c98b9d3a8e6ab76b762578cf2856e3b04ad8e42bfb23bb1e1.py
698
+ frame.type("#mytextarea", "hello") # types instantly
699
+ frame.type("#mytextarea", "world", delay=100) # types slower, like a user
700
+
701
+ ```
702
+
703
+
704
+
705
+ ## uncheck
706
+
707
+ ```
708
+ def uncheck(
709
+ selector,
710
+ force: nil,
711
+ noWaitAfter: nil,
712
+ position: nil,
713
+ timeout: nil,
714
+ trial: nil)
715
+ ```
716
+
717
+ This method checks an element matching `selector` by performing the following steps:
718
+ 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
719
+ 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
720
+ unchecked, this method returns immediately.
721
+ 1. Wait for [actionability](https://playwright.dev/python/docs/actionability) checks on the matched element, unless `force` option is set. If the
722
+ element is detached during the checks, the whole action is retried.
723
+ 1. Scroll the element into view if needed.
724
+ 1. Use [Page#mouse](./page#mouse) to click in the center of the element.
725
+ 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
726
+ 1. Ensure that the element is now unchecked. If not, this method throws.
727
+
728
+ When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
729
+ zero timeout disables this.
730
+
731
+ ## url
732
+
733
+ ```
734
+ def url
735
+ ```
736
+
737
+ Returns frame's url.
738
+
739
+ ## wait_for_function
740
+
741
+ ```
742
+ def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
743
+ ```
744
+
745
+ Returns when the `expression` returns a truthy value, returns that value.
746
+
747
+ The [Frame#wait_for_function](./frame#wait_for_function) can be used to observe viewport size change:
748
+
749
+ ```python sync title=example_2f82dcf15fa9338be87a4faf7fe7de3c542040924db1e1ad1c98468ec0f425ce.py
750
+ from playwright.sync_api import sync_playwright
751
+
752
+ def run(playwright):
753
+ webkit = playwright.webkit
754
+ browser = webkit.launch()
755
+ page = browser.new_page()
756
+ page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
757
+ page.main_frame.wait_for_function("() => window.x > 0")
758
+ browser.close()
759
+
760
+ with sync_playwright() as playwright:
761
+ run(playwright)
762
+
763
+ ```
764
+
765
+ To pass an argument to the predicate of `frame.waitForFunction` function:
766
+
767
+ ```python sync title=example_8b95be0fb4d149890f7817d9473428a50dc631d3a75baf89846648ca6a157562.py
768
+ selector = ".foo"
769
+ frame.wait_for_function("selector => !!document.querySelector(selector)", selector)
770
+
771
+ ```
772
+
773
+
774
+
775
+ ## wait_for_load_state
776
+
777
+ ```
778
+ def wait_for_load_state(state: nil, timeout: nil)
779
+ ```
780
+
781
+ Waits for the required load state to be reached.
782
+
783
+ This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed
784
+ when this method is called. If current document has already reached the required state, resolves immediately.
785
+
786
+ ```python sync title=example_fe41b79b58d046cda4673ededd4d216cb97a63204fcba69375ce8a84ea3f6894.py
787
+ frame.click("button") # click triggers navigation.
788
+ frame.wait_for_load_state() # the promise resolves after "load" event.
789
+
790
+ ```
791
+
792
+
793
+
794
+ ## expect_navigation
795
+
796
+ ```
797
+ def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
798
+ ```
799
+
800
+ Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
801
+ will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
802
+ History API usage, the navigation will resolve with `null`.
803
+
804
+ This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause
805
+ the frame to navigate. Consider this example:
806
+
807
+ ```python sync title=example_03f0ac17eb6c1ce8780cfa83c4ae15a9ddbfde3f96c96f36fdf3fbf9aac721f7.py
808
+ with frame.expect_navigation():
809
+ frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
810
+ # Resolves after navigation has finished
811
+
812
+ ```
813
+
814
+ > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
815
+ considered a navigation.
816
+
817
+ ## wait_for_selector
818
+
819
+ ```
820
+ def wait_for_selector(selector, state: nil, timeout: nil)
821
+ ```
822
+
823
+ Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
824
+ `detached`.
825
+
826
+ Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
827
+ the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
828
+ selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
829
+
830
+ This method works across navigations:
831
+
832
+ ```python sync title=example_a5b9dd4745d45ac630e5953be1c1815ae8e8ab03399fb35f45ea77c434f17eea.py
833
+ from playwright.sync_api import sync_playwright
834
+
835
+ def run(playwright):
836
+ chromium = playwright.chromium
837
+ browser = chromium.launch()
838
+ page = browser.new_page()
839
+ for current_url in ["https://google.com", "https://bbc.com"]:
840
+ page.goto(current_url, wait_until="domcontentloaded")
841
+ element = page.main_frame.wait_for_selector("img")
842
+ print("Loaded image: " + str(element.get_attribute("src")))
843
+ browser.close()
844
+
845
+ with sync_playwright() as playwright:
846
+ run(playwright)
847
+
848
+ ```
849
+
850
+
851
+
852
+ ## wait_for_url
853
+
854
+ ```
855
+ def wait_for_url(url, timeout: nil, waitUntil: nil)
856
+ ```
857
+
858
+ Waits for the frame to navigate to the given URL.
859
+
860
+ ```python sync title=example_86a9a19ec4c41e1a5ac302fbca9a3d3d6dca3fe3314e065b8062ddf5f75abfbd.py
861
+ frame.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
862
+ frame.wait_for_url("**/target.html")
863
+
864
+ ```
865
+
866
+