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

Copy Markdown View Source

FileChooser objects are dispatched by the page in the Page.on(:file_chooser) event.

# 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}).

Summary

Types

Options of set_files/3, see its docs.

t()

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

Functions

Returns input element associated with this file chooser.

Returns whether this file chooser accepts multiple files.

Returns page this file chooser belongs to.

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.

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

Types

set_files_options()

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

Options of set_files/3, see its docs.

t()

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

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

Functions

element(file_chooser)

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

Returns input element associated with this file chooser.

Since Playwright 1.8.

is_multiple(file_chooser)

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

Returns whether this file chooser accepts multiple files.

Since Playwright 1.8.

page(file_chooser)

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

Returns page this file chooser belongs to.

Since Playwright 1.8.

set_files(file_chooser, files, options \\ [])

@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

set_files!(file_chooser, files, options \\ [])

@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.