You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For scenarios involving just one page, it is possible to create a new page
85
-
without explicitly creating a browser context through a convenience API. This
86
-
will create a new context internally, and closing the page will close the
87
-
context as well.
97
+
## Selectors
88
98
89
-
```js
90
-
constbrowser=awaitwebkit.launch();
91
-
constpage=awaitbrowser.newPage();
92
-
```
99
+
<br/>
100
+
101
+
## Auto-waiting
102
+
103
+
<br/>
93
104
94
105
## Execution contexts
95
106
96
107
Playwright scripts run in your Node.js environment. You page scripts run in the page environment. Those environments don't intersect, they are running in different virtual machines in different processes and potentially on different computers.
97
108
98
109
IMAGE PLACEHOLDER
99
110
100
-
Playwright exposes APIs to execute the JavaScript code in the context of the web page and allows calling back into the Node.js environment from your web page.
101
-
102
-
### Using the Evaluate API
103
-
104
111
The [`page.evaluate`](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatepagefunction-arg) API can run a JavaScript function in the context
105
112
of the web page and bring results back to the Node.js environment. Globals like
106
113
`window` and `document` along with the web page runtime can be used in `evaluate`.
This is the easiest way to check and uncheck a checkbox. This method can be used on the `input[type=checkbox]` and on the `label` associated with that input.
43
56
44
-
#### API reference
57
+
#### Reference
45
58
46
-
-[`page.check(selector[, options])`](./api.md#pagecheckselector-options) — on the main frame
47
-
-[`page.uncheck(selector[, options])`](./api.md#pageuncheckselector-options) — on the main frame
48
-
-[`frame.check(selector[, options])`](./api.md#framecheckselector-options) — on a specific frame
49
-
-[`frame.uncheck(selector[, options])`](./api.md#frameuncheckselector-options) — on a specific frame
50
-
-[`elementHandle.check(value[, options])`](./api.md#elementhandleuncheckoptions) — on a particular element
51
-
-[`elementHandle.uncheck(value[, options])`](./api.md#elementhandleuncheckoptions) — on a particular element
59
+
-[page.check(selector[, options])](./api.md#pagecheckselector-options) — main frame
60
+
-[page.uncheck(selector[, options])](./api.md#pageuncheckselector-options) — main frame
61
+
-[frame.check(selector[, options])](./api.md#framecheckselector-options) — given frame
62
+
-[frame.uncheck(selector[, options])](./api.md#frameuncheckselector-options) — given frame
63
+
-[elementHandle.check(value[, options])](./api.md#elementhandleuncheckoptions) — given element
64
+
-[elementHandle.uncheck(value[, options])](./api.md#elementhandleuncheckoptions) — given element
52
65
53
66
<br/>
54
67
55
-
## Select an option
68
+
## Select options
56
69
57
70
```js
58
71
// <select id=colors>
@@ -71,46 +84,98 @@ You can specify option `value`, `label` or `elementHandle` to select. Multiple o
-[page.click(selector[, options])](./api.md#pageclickselector-options) — main frame
146
+
-[frame.click(selector[, options])](./api.md#frameclickselector-options) — given frame
147
+
-[elementHandle.click([options])](./api.md#elementhandleclickoptions) — given element
148
+
-[page.dblclick(selector[, options])](./api.md#pagedblclickselector-options) — main frame
149
+
-[frame.dblclick(selector[, options])](./api.md#framedblclickselector-options) — given frame
150
+
-[elementHandle.dblclick([options])](./api.md#elementhandledblclickoptions) — given element
151
+
-[page.hover(selector[, options])](./api.md#pagehoverselector-options) — main frame
152
+
-[frame.hover(selector[, options])](./api.md#framehoverselector-options) — given frame
153
+
-[elementHandle.hover([options])](./api.md#elementhandlehoveroptions) — given element
154
+
155
+
<br/>
156
+
157
+
## Type characters
96
158
97
159
```js
98
160
// <textarea id=area></textarea>
161
+
99
162
awaitpage.type('#area', 'Hello World!');
100
163
```
101
164
102
-
Sometimes it is important to type into the focused field character by character, as if it was the user with the real keyboard. This method will emit all the necessary keyboard events, with all the `keydown`, `keyup`, `keypress` events in place. You can even specify the optional `delay` between the key presses to simulate real user behavior.
165
+
Note that most of the time, [`page.fill`](#text-input) will just work. You only need to type characters if there is special keyboard handling on the page.
166
+
167
+
But sometimes it is important to type into the field character by character, as if it was a user with a real keyboard. This method will emit all the necessary keyboard events, with all the `keydown`, `keyup`, `keypress` events in place. You can even specify the optional `delay` between the key presses to simulate real user behavior.
103
168
104
-
#### API reference
169
+
#### Reference
105
170
106
-
- [`page.type(selector, text[, options])`](./api.md#pagetypeselector-text-options) — on the main frame
107
-
- [`frame.type(selector, text[, options])`](./api.md#frametypeselector-text-options) — on a specific frame
108
-
- [`elementHandle.type(text[, options])`](./api.md#elementhandletypetext-options) — on a particular element
109
-
- [`keyboard.type(text[, options])`](./api.md#keyboardtypetext-options) — wherever the current focus is
171
+
-[page.type(selector, text[, options])](./api.md#pagetypeselector-text-options) — main frame
172
+
-[frame.type(selector, text[, options])](./api.md#frametypeselector-text-options) — given frame
173
+
-[elementHandle.type(text[, options])](./api.md#elementhandletypetext-options) — given element
174
+
-[keyboard.type(text[, options])](./api.md#keyboardtypetext-options) — focused element
110
175
111
176
<br/>
112
177
113
-
## Press a key, enter keyboard shortcut
178
+
## Keys and shortcuts
114
179
115
180
```js
116
181
// <button id=submit></button>
@@ -159,9 +224,65 @@ Shortcuts such as `"Control+o"` or `"Control+Shift+T"` are supported as well. Wh
159
224
Note that you still need to specify the capital `A` in `Shift-A` to produce the capital character. `Shift-a` produces a lower-case one as if you had the `CapsLock` toggled.
160
225
161
226
162
-
#### API reference
227
+
#### Reference
228
+
229
+
-[page.press(selector, key[, options])](./api.md#pagepressselector-key-options) — main frame
230
+
-[frame.press(selector, key[, options])](./api.md#framepressselector-key-options) — given frame
231
+
-[elementHandle.press(key[, options])](./api.md#elementhandlepresskey-options) — given element
232
+
-[keyboard.press(key[, options])](./api.md#keyboardpresskey-options) — focused element
163
233
164
-
- [`page.press(selector, key[, options])`](./api.md#pagepressselector-key-options) — on the main frame
165
-
- [`frame.press(selector, key[, options])`](./api.md#framepressselector-key-options) — on a specific frame
166
-
- [`elementHandle.press(key[, options])`](./api.md#elementhandlepresskey-options) — on a particular element
167
-
- [`keyboard.press(key[, options])`](./api.md#keyboardpresskey-options) — wherever the current focus is
You can select input files for upload using the `page.setInputFiles` method. It expects first argument to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) with the type `"file"`. Multiple files can be passed in the array. If some of the file paths are relative, they are resolved relative to the [current working directory](https://nodejs.org/api/process.html#process_process_cwd). Empty array clears the selected files.
0 commit comments