Playwright Other APIs

This appendix lists the APIs for helper classes such as Dialog, Download, Video, Tracing.


Dialog Class

MethodDescription
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

MethodDescription
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

MethodDescription
fileChooser.setFiles(files, options?)Select files
fileChooser.isMultiple()Whether it is multi-select mode
fileChooser.page()Page of the file chooser

ConsoleMessage Class

MethodDescription
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

MethodDescription
video.saveAs(path)Save video to file
video.delete()Delete video file
video.path()Video file path

Tracing Class

MethodDescription
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

MethodDescription
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

MethodDescription
selectors.register(name, script, options?)Register custom selector engine

ElementHandle Class

MethodDescription
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

MethodDescription
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

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

Worker Class

Method/EventDescription
worker.url()Worker URL
worker.evaluate(fn, arg?)Evaluate JS in the worker
worker.on('close', handler)Worker close event

Frame Class

MethodDescription
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

ClassDescription
PlaywrightExceptionGeneral Playwright exception
TimeoutErrorTimeout error (assertion timeout, operation timeout, etc.)
Other extensions