Playwright Other APIs
This appendix lists the APIs for helper classes such as Dialog, Download, Video, Tracing.
Dialog Class
| Method | Description |
dialog.accept(promptText?) | Accept dialog |
dialog.dismiss() | Dismiss dialog |
dialog.message() | Dialog message |
dialog.type() | Dialog type:'alert' | 'confirm' | 'prompt' | 'beforeunload' |
dialog.defaultValue() | Dialog default input value |
dialog.page() | Page of the dialog |
Download Class
| Method | Description |
download.saveAs(path) | Save file to the specified path |
download.suggestedFilename() | Get the suggested file name |
download.url() | Download URL |
download.page() | Page of the download |
download.failure() | Download failure info (returns null if no failure) |
download.delete() | Delete the downloaded file |
FileChooser Class
| Method | Description |
fileChooser.setFiles(files, options?) | Select files |
fileChooser.isMultiple() | Whether it is multi-select mode |
fileChooser.page() | Page of the file chooser |
ConsoleMessage Class
| Method | Description |
consoleMessage.type() | Message type:'log' | 'error' | 'warning' | 'info' | 'debug' |
consoleMessage.text() | Message text |
consoleMessage.location() | Message source location |
consoleMessage.args() | Message arguments (array of JSHandle) |
Video Class
| Method | Description |
video.saveAs(path) | Save video to file |
video.delete() | Delete video file |
video.path() | Video file path |
Tracing Class
| Method | Description |
tracing.start(options?) | Start recording trace |
tracing.startChunk(options?) | Start a new trace chunk |
tracing.stopChunk(options?) | Stop trace chunk and save |
tracing.stop(options?) | Stop recording and save trace |
Clock Class
| Method | Description |
clock.install(options?) | Install fake clock |
clock.pauseAt(time) | Pause at the specified time |
clock.resume() | Resume execution |
clock.setFixedTime(time) | Set fixed time |
clock.fastForward(time) | Fast-forward time |
clock.runFor(time) | Run for the specified duration |
Selectors Class
| Method | Description |
selectors.register(name, script, options?) | Register custom selector engine |
ElementHandle Class
| Method | Description |
elementHandle.click(options?) | Click |
elementHandle.fill(value) | Fill text |
elementHandle.screenshot(options?) | Element screenshot |
elementHandle.boundingBox() | Get bounding box |
elementHandle.getAttribute(name) | Get attribute |
elementHandle.textContent() | Get text |
elementHandle.ownerFrame() | Owner frame |
JSHandle Class
| Method | Description |
jsHandle.evaluate(fn, arg?) | Evaluate JS |
jsHandle.getProperty(name) | Get property |
jsHandle.getProperties() | Get all properties |
jsHandle.jsonValue() | Get JSON value |
jsHandle.dispose() | Release resources |
CDPSession Class
| Method | Description |
cdpSession.send(method, params?) | Send CDP command |
cdpSession.detach() | Detach CDP session |
Worker Class
| Method/Event | Description |
worker.url() | Worker URL |
worker.evaluate(fn, arg?) | Evaluate JS in the worker |
worker.on('close', handler) | Worker close event |
Frame Class
| Method | Description |
frame.name() | Frame name |
frame.url() | Frame URL |
frame.goto(url, options?) | Frame navigation |
frame.locator(selector) | Locate via CSS/XPath |
frame.getByRole(role, options?) | Locate by role |
frame.getByText(text) | Locate by text |
frame.evaluate(fn, arg?) | Evaluate JS |
frame.content() | Get HTML content |
frame.parentFrame() | Parent frame |
frame.childFrames() | Child frame list |
Error Classes
| Class | Description |
PlaywrightException | General Playwright exception |
TimeoutError | Timeout error (assertion timeout, operation timeout, etc.) |
Other extensions