Playwright.Dialog (Playwright v1.65.0-rc.3)

Copy Markdown View Source

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

Types

t()

A Dialog handle. Compare handles with ==, their fields are internal.

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

t()

@type t() :: %Playwright.Dialog{
  conn: term(),
  guid: term(),
  initializer: term(),
  table: term(),
  type: term()
}

A Dialog handle. Compare handles with ==, their fields are internal.

Functions

accept(dialog, prompt_text \\ nil)

@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's type is not prompt. Optional.

accept!(dialog, prompt_text \\ nil)

@spec accept!(t(), String.t() | nil) :: :ok

Like accept/2, but returns the value and raises on error.

default_value(dialog)

@spec default_value(t()) :: String.t()

If dialog is prompt, returns default prompt value. Otherwise, returns empty string.

Since Playwright 1.8.

dismiss(dialog)

@spec dismiss(t()) :: :ok | {:error, Playwright.error()}

Returns when the dialog has been dismissed.

Since Playwright 1.8.

dismiss!(dialog)

@spec dismiss!(t()) :: :ok

Like dismiss/1, but returns the value and raises on error.

message(dialog)

@spec message(t()) :: String.t()

A message displayed in the dialog.

Since Playwright 1.8.

page(dialog)

@spec page(t()) :: nil | Playwright.Page.t()

The page that initiated this dialog, if available.

Since Playwright 1.34.

type(dialog)

@spec type(t()) :: String.t()

Returns dialog's type, can be one of alert, beforeunload, confirm or prompt.

Since Playwright 1.8.