# `Playwright.Dialog`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.3/lib/playwright/api/dialog.ex#L7)

[`Dialog`](`Playwright.Dialog`) objects are dispatched by page via the [`Page.on(:dialog)`](Playwright.Page.html#module-dialog) event.

An example of using [`Dialog`](`Playwright.Dialog`) class:

```elixir
# 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 {: .info}
>
> Dialogs are dismissed automatically, unless there is a [`Page.on(:dialog)`](Playwright.Page.html#module-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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) 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}`).

# `t`

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

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

# `accept`

```elixir
@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!`

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

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

# `default_value`

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

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

*Since Playwright 1.8.*

# `dismiss`

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

Returns when the dialog has been dismissed.

*Since Playwright 1.8.*

# `dismiss!`

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

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

# `message`

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

A message displayed in the dialog.

*Since Playwright 1.8.*

# `page`

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

The page that initiated this dialog, if available.

*Since Playwright 1.34.*

# `type`

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

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

*Since Playwright 1.8.*

---

*Consult [api-reference.md](api-reference.md) for complete listing*
