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.
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
@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.
A FileChooser handle. Compare handles with ==, their fields are internal.
Functions
@spec element(t()) :: Playwright.ElementHandle.t()
Returns input element associated with this file chooser.
Since Playwright 1.8.
Returns whether this file chooser accepts multiple files.
Since Playwright 1.8.
@spec page(t()) :: Playwright.Page.t()
Returns page this file chooser belongs to.
Since Playwright 1.8.
@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(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. 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 usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@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.