Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Playwright Other APIs

Playwright Other APIs

This appendix lists APIs of auxiliary classes such as Dialog, Download, Video, and Tracing.


Dialog class

Method Description
dialog.accept(promptText?) Confirmation dialog
dialog.dismiss() Dismiss dialog
dialog.message() Dialog message
dialog.type() Dialog types:'alert' | 'confirm' | 'prompt' | 'beforeunload'
dialog.defaultValue() Dialog default input value
dialog.page() Page the dialog belongs to

Download class

Method Description
download.saveAs(path) Save file to a specified path
download.suggestedFilename() Get suggested filename
download.url() Download URL
download.page() Owning page
download.failure() Download failure message (returns null if no failure)
download.delete() Delete the downloaded file

FileChooser class

Method Description
fileChooser.setFiles(files, options?) Select File
fileChooser.isMultiple() Whether multi-select mode
fileChooser.page() Owning page

ConsoleMessage class

Method Description
consoleMessage.type() Message types:'log' | 'error' | 'warning' | 'info' | 'debug'
consoleMessage.text() Message text
consoleMessage.location() Message source location
consoleMessage.args() Message arguments (JSHandle array)

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 a specified time
clock.resume() Resume execution
clock.setFixedTime(time) Set fixed time
clock.fastForward(time) Fast-forward time
clock.runFor(time) Run for a specified time

Selectors class

Method Description
selectors.register(name, script, options?) Register a custom selector engine

ElementHandle class

Method Description
elementHandle.click(options?) Click
elementHandle.fill(value) Fill in text
elementHandle.screenshot(options?) Element screenshot
elementHandle.boundingBox() Get position and size
elementHandle.getAttribute(name) Get attribute
elementHandle.textContent() Get text
elementHandle.ownerFrame() Owning frame

JSHandle class

Method Description
jsHandle.evaluate(fn, arg?) Execute JS
jsHandle.getProperty(name) Get attribute
jsHandle.getProperties() Get all properties
jsHandle.jsonValue() Get JSON value
jsHandle.dispose() Dispose resources

CDPSession class

Method Description
cdpSession.send(method, params?) Send CDP command
cdpSession.detach() Detach CDP session

Worker class

Methods/Events Description
worker.url() Worker URL
worker.evaluate(fn, arg?) Execute JS in 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) CSS/XPath locating
frame.getByRole(role, options?) Locate by role
frame.getByText(text) Locate by text
frame.evaluate(fn, arg?) Execute 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, action timeout, etc.)