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

[`FileChooser`](`Playwright.FileChooser`) objects are dispatched by the page in the [`Page.on(:file_chooser)`](Playwright.Page.html#module-file_chooser) event.

```elixir
# Start waiting for file chooser before clicking. Note no await.
file_chooser_promise = Page.wait_for_event(page, :file_chooser)
Page.get_by_text(page, "Upload file") |> Locator.click!()
file_chooser = Promise.await!(file_chooser_promise)
FileChooser.set_files!(file_chooser, Path.join(__DIR__, "myfile.pdf"))
```

*Since Playwright 1.8.*

The examples alias the modules they use (`alias Playwright.{Locator, Page}`).

# `set_files_options`

```elixir
@type set_files_options() ::
  [
    no_wait_after: boolean(),
    signal: Playwright.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:no_wait_after) =&gt; boolean(),
      optional(:signal) =&gt; Playwright.AbortSignal.t(),
      optional(:timeout) =&gt; number() | :infinity
    }
```

Options of `set_files/3`, see its docs.

# `t`

```elixir
@type t() :: %Playwright.FileChooser{
  _elementHandle: term(),
  _isMultiple: term(),
  _page: term()
}
```

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

# `element`

```elixir
@spec element(t()) :: Playwright.ElementHandle.t()
```

Returns input element associated with this file chooser.

*Since Playwright 1.8.*

# `is_multiple`

```elixir
@spec is_multiple(t()) :: boolean()
```

Returns whether this file chooser accepts multiple files.

*Since Playwright 1.8.*

# `page`

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

Returns page this file chooser belongs to.

*Since Playwright 1.8.*

# `set_files`

```elixir
@spec set_files(
  t(),
  String.t()
  | [String.t()]
  | %{name: String.t(), mimeType: String.t(), buffer: binary()}
  | [%{name: String.t(), mimeType: String.t(), buffer: binary()}],
  set_files_options()
) :: :ok | {:error, Playwright.error()}
```

Sets the value of the file input this chooser is associated with. If some of the `files` are relative paths, then
they are resolved relative to the current working directory. For empty array, clears the selected files.

*Since Playwright 1.8.*

## Arguments

* `files`
  * `:name` - File name
  * `:mimeType` - File type
  * `:buffer` - File content

## Options

* `:no_wait_after` (`t:boolean/0`) - This option has no effect.
* `:signal` (`t:Playwright.AbortSignal.t/0`) - *Since Playwright 1.62.* Allows to cancel the operation using an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the operation will be aborted and fail.
  Note that providing a signal does not disable the default timeout, which can be changed using `Playwright.BrowserContext.set_default_timeout/2` or `Playwright.Page.set_default_timeout/2`; pass `timeout: 0` to disable the timeout entirely.

  In Elixir, a `Playwright.AbortSignal` (`Playwright.AbortController.signal/1`).
* `:timeout` (`t:number/0` | `:infinity`) - Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by
  using the `Playwright.BrowserContext.set_default_timeout/2` or
  `Playwright.Page.set_default_timeout/2` methods.

  In Elixir, `:infinity` is the same as `0`: no timeout.

# `set_files!`

```elixir
@spec set_files!(
  t(),
  String.t()
  | [String.t()]
  | %{name: String.t(), mimeType: String.t(), buffer: binary()}
  | [%{name: String.t(), mimeType: String.t(), buffer: binary()}],
  set_files_options()
) :: :ok
```

Like `set_files/3`, but returns the value and raises on error.

---

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