Skip to main content

Dialogs

Handle browser dialogs (alert, confirm, prompt) that block page interaction.

Commands

CommandDescription
dialog-accept [prompt]Accept a dialog, optionally providing prompt text
dialog-dismissDismiss (cancel) a dialog

How a dialog is reported

While a dialog is open, every command reports it under a Modal state section and tells you which command clears it:

### Modal state
- ["confirm" dialog with message "Are you sure you want to delete this?"]: can be handled by dialog-accept or dialog-dismiss

Nothing else can proceed until it is handled.

Alert dialogs

$ playwright-cli click e5
### Modal state
- ["alert" dialog with message "Item has been deleted."]: can be handled by dialog-accept or dialog-dismiss

$ playwright-cli dialog-accept

Confirm dialogs

$ playwright-cli click e10
### Modal state
- ["confirm" dialog with message "Are you sure you want to delete this?"]: can be handled by dialog-accept or dialog-dismiss

# Accept (OK)
$ playwright-cli dialog-accept

# Or dismiss (Cancel)
$ playwright-cli dialog-dismiss

Prompt dialogs

$ playwright-cli click e8
### Modal state
- ["prompt" dialog with message "Enter your name:"]: can be handled by dialog-accept or dialog-dismiss

# Accept with text
$ playwright-cli dialog-accept "Alice"

# Or dismiss (cancels the prompt)
$ playwright-cli dialog-dismiss

File choosers

A file chooser is reported the same way, and is cleared with upload rather than the dialog commands:

### Modal state
- [File chooser]: can be handled by upload
playwright-cli upload /abs/path/to/document.pdf

Workflow

$ playwright-cli click e12
### Modal state
- ["confirm" dialog with message "Discard unsaved changes?"]: can be handled by dialog-accept or dialog-dismiss

$ playwright-cli dialog-accept

$ playwright-cli snapshot
# Page now shows updated state after dialog was accepted