Dialog objects are dispatched by page via the Page.on(:dialog) event.
An example of using Dialog class:
# Or Playwright.firefox/1 or Playwright.webkit/1.
browser = Playwright.chromium(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
Page.on(page, :dialog, fn dialog ->
IO.puts(Dialog.message(dialog))
Dialog.dismiss!(dialog)
end)
Page.evaluate!(page, "() => alert('1')")
Browser.close!(browser)Note
Dialogs are dismissed automatically, unless there is a Page.on(:dialog) listener.
When listener is present, it must either Playwright.Dialog.accept/2 or Playwright.Dialog.dismiss/1 the dialog - otherwise the page will freeze waiting for the dialog, and actions like click will never finish.
Since Playwright 1.8.
The examples alias the modules they use (alias Playwright.{Locator, Page}).
Summary
Functions
Returns when the dialog has been accepted.
Like accept/2, but returns the value and raises on error.
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
Returns when the dialog has been dismissed.
Like dismiss/1, but returns the value and raises on error.
A message displayed in the dialog.
The page that initiated this dialog, if available.
Returns dialog's type, can be one of alert, beforeunload, confirm or prompt.
Types
Functions
@spec accept(t(), String.t() | nil) :: :ok | {:error, Playwright.error()}
Returns when the dialog has been accepted.
Since Playwright 1.8.
Arguments
prompt_text- A text to enter in prompt. Does not cause any effects if the dialog'stypeis not prompt. Optional.
Like accept/2, but returns the value and raises on error.
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
Since Playwright 1.8.
@spec dismiss(t()) :: :ok | {:error, Playwright.error()}
Returns when the dialog has been dismissed.
Since Playwright 1.8.
@spec dismiss!(t()) :: :ok
Like dismiss/1, but returns the value and raises on error.
A message displayed in the dialog.
Since Playwright 1.8.
@spec page(t()) :: nil | Playwright.Page.t()
The page that initiated this dialog, if available.
Since Playwright 1.34.
Returns dialog's type, can be one of alert, beforeunload, confirm or prompt.
Since Playwright 1.8.