Dialog

Playwright\Dialog\DialogInterface

Represents a page dialog. Dialogs expose alerts, confirms, prompts, and beforeunload messages. Accept or dismiss them before the page can continue its dialog flow.

Methods

page()

PageInterface

Returns the owning page. The page emitted the dialog event that created this object. Use it to associate the dialog with the active browser context.

function page(): PageInterface

type()

string

Returns the dialog type. Typical values include alert, confirm, prompt, and beforeunload. The type determines whether prompt text has any effect when accepting.

function type(): string

message()

string

Returns the dialog message. The browser supplies this text when opening the dialog. Use it to distinguish dialogs emitted by the same page.

function message(): string

defaultValue()

?string

Returns the default prompt value. Prompt dialogs can prefill a value supplied by the page. Other dialog types can return null.

function defaultValue(): ?string

accept()

void

Accepts the dialog. Supply prompt text to replace the default value for a prompt dialog. The page resumes once the browser processes the acceptance.

function accept(?string $promptText = null): void

dismiss()

void

Dismisses the dialog. A confirm dialog resolves as cancelled and a prompt receives no value. The page resumes once the browser processes the dismissal.

function dismiss(): void