At every point of time, page exposes its current frame tree via the Playwright.Page.main_frame/1 and
Playwright.Frame.child_frames/1 methods.
Frame object's lifecycle is controlled by three events, dispatched on the page object:
Page.on(:frame_attached)- fired when the frame gets attached to the page. A Frame can be attached to the page only once.Page.on(:frame_navigated)- fired when the frame commits navigation to a different URL.Page.on(:frame_detached)- fired when the frame gets detached from the page. A Frame can be detached from the page only once.
An example of dumping frame tree:
dump_frame_tree = fn dump_frame_tree, frame, indent ->
IO.puts(indent <> Frame.url(frame))
for child <- Frame.child_frames(frame), do: dump_frame_tree.(dump_frame_tree, child, indent <> " ")
end
# Or Playwright.chromium/1 or Playwright.webkit/1.
browser = Playwright.firefox(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
Page.goto!(page, "https://www.google.com/chrome/browser/canary.html")
dump_frame_tree.(dump_frame_tree, Page.main_frame(page), "")
Browser.close!(browser)Since Playwright 1.8.
The examples alias the modules they use (alias Playwright.{Locator, Page}).
Summary
Types
Options of add_script_tag/2, see its docs.
Options of add_style_tag/2, see its docs.
Options of check/3, see its docs.
Options of click/3, see its docs.
Options of content/2, see its docs.
Options of dblclick/3, see its docs.
Options of dispatch_event/5, see its docs.
Options of drag_and_drop/4, see its docs.
Options of evaluate_handle/4, see its docs.
Options of evaluate/4, see its docs.
Options of expect_navigation/3, see its docs.
Options of fill/4, see its docs.
Options of focus/3, see its docs.
Options of get_attribute/4, see its docs.
Options of get_by_alt_text/3, see its docs.
Options of get_by_label/3, see its docs.
Options of get_by_placeholder/3, see its docs.
Options of get_by_role/3, see its docs.
Options of get_by_text/3, see its docs.
Options of get_by_title/3, see its docs.
Options of goto/3, see its docs.
Options of hover/3, see its docs.
Options of inner_html/3, see its docs.
Options of inner_text/3, see its docs.
Options of input_value/3, see its docs.
Options of is_checked/3, see its docs.
Options of is_disabled/3, see its docs.
Options of is_editable/3, see its docs.
Options of is_enabled/3, see its docs.
Options of is_hidden/3, see its docs.
Options of is_visible/3, see its docs.
Options of locator/3, see its docs.
Options of press/4, see its docs.
Options of query_selector/3, see its docs.
Options of select_option/4, see its docs.
Options of set_checked/4, see its docs.
Options of set_content/3, see its docs.
Options of set_input_files/4, see its docs.
A Frame handle. Compare handles with ==, their fields are internal.
Options of tap/3, see its docs.
Options of text_content/3, see its docs.
Options of type/4, see its docs.
Options of uncheck/3, see its docs.
Options of wait_for_function/4, see its docs.
Options of wait_for_load_state/3, see its docs.
Options of wait_for_navigation/2, see its docs.
Options of wait_for_selector/3, see its docs.
Options of wait_for_url/3, see its docs.
Functions
Returns the added tag when the script's onload fires or when the script content was injected into frame.
Like add_script_tag/2, but returns the value and raises on error.
Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
Like add_style_tag/2, but returns the value and raises on error.
This method checks an element matching selector by performing the following steps
Like check/3, but returns the value and raises on error.
Since Playwright 1.8.
This method clicks an element matching selector by performing the following steps
Like click/3, but returns the value and raises on error.
Gets the full HTML contents of the frame, including the doctype.
Like content/2, but returns the value and raises on error.
This method double clicks an element matching selector by performing the following steps
Like dblclick/3, but returns the value and raises on error.
The snippet below dispatches the click event on the element. Regardless of the visibility state of the element, click
is dispatched. This is equivalent to calling
element.click().
Like dispatch_event/5, but returns the value and raises on error.
Since Playwright 1.13.
Like drag_and_drop/4, but returns the value and raises on error.
Returns the return value of expression.
Like eval_on_selector/4, but returns the value and raises on error.
Returns the return value of expression.
Like eval_on_selector_all/4, but returns the value and raises on error.
Returns the return value of expression.
Like evaluate/4, but returns the value and raises on error.
Returns the return value of expression as a JSHandle.
Like evaluate_handle/4, but returns the value and raises on error.
Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
returns the response of the last redirect. In case of navigation to a different anchor or navigation due to
History API usage, the navigation returns nil.
Like expect_navigation/3, but returns the value and raises on error.
This method waits for an element matching selector, waits for actionability checks, focuses the element, fills it and triggers an input event after filling. Note that you can pass an empty string to clear the input field.
Like fill/4, but returns the value and raises on error.
This method fetches an element with selector and focuses it. If there's no element matching
selector, the method waits until a matching element appears in the DOM.
Like focus/3, but returns the value and raises on error.
Returns the frame or iframe element handle which corresponds to this frame.
Like frame_element/1, but returns the value and raises on error.
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
Returns element attribute value.
Like get_attribute/4, but returns the value and raises on error.
Allows locating elements by their alt text.
Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.
Allows locating input elements by the placeholder text.
Allows locating elements by their ARIA role, ARIA attributes and accessible name.
Locate element by the test id.
Allows locating elements that contain given text.
Allows locating elements by their title attribute.
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the last redirect.
Like goto/3, but returns the value and raises on error.
This method hovers over an element matching selector by performing the following steps
Like hover/3, but returns the value and raises on error.
Returns element.innerHTML.
Like inner_html/3, but returns the value and raises on error.
Returns element.innerText.
Like inner_text/3, but returns the value and raises on error.
Returns input.value for the selected <input> or <textarea> or <select> element.
Like input_value/3, but returns the value and raises on error.
Returns whether the element is checked. Fails if the element is not a checkbox or radio input.
Like is_checked/3, but returns the value and raises on error.
Returns true if the frame has been detached, or false otherwise.
Returns whether the element is disabled, the opposite of enabled.
Like is_disabled/3, but returns the value and raises on error.
Returns whether the element is editable.
Like is_editable/3, but returns the value and raises on error.
Returns whether the element is enabled.
Like is_enabled/3, but returns the value and raises on error.
Returns whether the element is hidden, the opposite of visible. selector that does not match any elements is considered hidden.
Like is_hidden/3, but returns the value and raises on error.
Returns whether the element is visible. selector that does not match any elements is considered not visible.
Like is_visible/3, but returns the value and raises on error.
The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
Returns frame's name attribute as specified in the tag.
Returns the page containing this frame.
Parent frame, if any. Detached frames and main frames return nil.
key can specify the intended
keyboardEvent.key value or a single character to
generate the text for. A superset of the key values can be found
here. Examples of the keys are
Like press/4, but returns the value and raises on error.
Returns the ElementHandle pointing to the frame element.
Like query_selector/3, but returns the value and raises on error.
Returns the ElementHandles pointing to the frame elements.
Like query_selector_all/2, but returns the value and raises on error.
This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.
Like select_option/4, but returns the value and raises on error.
This method checks or unchecks an element matching selector by performing the following steps
Like set_checked/4, but returns the value and raises on error.
This method internally calls document.write(), inheriting all its specific characteristics and behaviors.
Like set_content/3, but returns the value and raises on error.
Sets the value of the file input to these file paths or files. 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_input_files/4, but returns the value and raises on error.
This method taps an element matching selector by performing the following steps
Like tap/3, but returns the value and raises on error.
Returns element.textContent.
Like text_content/3, but returns the value and raises on error.
Returns the page title.
Like title/1, but returns the value and raises on error.
Sends a keydown, keypress/input, and keyup event for each character in the text. Playwright.Frame.type/4 can be used to
send fine-grained keyboard events. To fill values in form fields, use Playwright.Frame.fill/4.
Like type/4, but returns the value and raises on error.
This method checks an element matching selector by performing the following steps
Like uncheck/3, but returns the value and raises on error.
Returns frame's url.
Returns when the expression returns a truthy value, returns that value.
Like wait_for_function/4, but returns the value and raises on error.
Waits for the required load state to be reached.
Like wait_for_load_state/3, but returns the value and raises on error.
Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
returns the response of the last redirect. In case of navigation to a different anchor or navigation due to
History API usage, the navigation returns nil.
Like wait_for_navigation/2, but awaits the promise: Playwright.Promise.await!(wait_for_navigation(...)), the value or a raise.
Returns when element specified by selector satisfies :state option. Returns nil if waiting for hidden or
detached.
Like wait_for_selector/3, but returns the value and raises on error.
Waits for the given timeout in milliseconds. It rejects :infinity.
Like wait_for_timeout/2, but returns the value and raises on error.
Waits for the frame to navigate to the given URL.
Like wait_for_url/3, but returns the value and raises on error.
Types
@type add_script_tag_options() :: [content: String.t(), path: String.t(), type: String.t(), url: String.t()] | %{ optional(:content) => String.t(), optional(:path) => String.t(), optional(:type) => String.t(), optional(:url) => String.t() }
Options of add_script_tag/2, see its docs.
@type add_style_tag_options() :: [content: String.t(), path: String.t(), url: String.t()] | %{ optional(:content) => String.t(), optional(:path) => String.t(), optional(:url) => String.t() }
Options of add_style_tag/2, see its docs.
@type check_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of check/3, see its docs.
@type click_options() :: [ button: :left | :right | :middle, click_count: integer(), delay: number(), force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:button) => :left | :right | :middle, optional(:click_count) => integer(), optional(:delay) => number(), optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of click/3, see its docs.
@type content_options() :: [{:include_shadow, boolean()}] | %{optional(:include_shadow) => boolean()}
Options of content/2, see its docs.
@type dblclick_options() :: [ button: :left | :right | :middle, delay: number(), force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:button) => :left | :right | :middle, optional(:delay) => number(), optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of dblclick/3, see its docs.
@type dispatch_event_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of dispatch_event/5, see its docs.
@type drag_and_drop_options() :: [ force: boolean(), no_wait_after: boolean(), scroll: :auto | :none, signal: Playwright.AbortSignal.t(), source_position: %{x: number(), y: number()}, steps: integer(), strict: boolean(), target_position: %{x: number(), y: number()}, timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:source_position) => %{x: number(), y: number()}, optional(:steps) => integer(), optional(:strict) => boolean(), optional(:target_position) => %{x: number(), y: number()}, optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of drag_and_drop/4, see its docs.
@type evaluate_handle_options() :: [{:expose_functions, boolean()}] | %{optional(:expose_functions) => boolean()}
Options of evaluate_handle/4, see its docs.
@type evaluate_options() :: [{:expose_functions, boolean()}] | %{optional(:expose_functions) => boolean()}
Options of evaluate/4, see its docs.
@type fill_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of fill/4, see its docs.
@type focus_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of focus/3, see its docs.
@type get_attribute_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of get_attribute/4, see its docs.
Options of get_by_alt_text/3, see its docs.
Options of get_by_label/3, see its docs.
Options of get_by_placeholder/3, see its docs.
@type get_by_role_options() :: [ checked: boolean(), description: String.t() | Regex.t() | Playwright.RegExp.t(), disabled: boolean(), exact: boolean(), expanded: boolean(), include_hidden: boolean(), level: integer(), name: String.t() | Regex.t() | Playwright.RegExp.t(), pressed: boolean(), selected: boolean() ] | %{ optional(:checked) => boolean(), optional(:description) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:disabled) => boolean(), optional(:exact) => boolean(), optional(:expanded) => boolean(), optional(:include_hidden) => boolean(), optional(:level) => integer(), optional(:name) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:pressed) => boolean(), optional(:selected) => boolean() }
Options of get_by_role/3, see its docs.
Options of get_by_text/3, see its docs.
Options of get_by_title/3, see its docs.
@type goto_options() :: [ referer: String.t(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:referer) => String.t(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of goto/3, see its docs.
@type hover_options() :: [ force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of hover/3, see its docs.
@type inner_html_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of inner_html/3, see its docs.
@type inner_text_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of inner_text/3, see its docs.
@type input_value_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of input_value/3, see its docs.
@type is_checked_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_checked/3, see its docs.
@type is_disabled_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_disabled/3, see its docs.
@type is_editable_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_editable/3, see its docs.
@type is_enabled_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_enabled/3, see its docs.
@type is_visible_options() :: [strict: boolean(), timeout: number() | :infinity] | %{ optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_visible/3, see its docs.
@type locator_options() :: [ has: Playwright.Locator.t(), has_not: Playwright.Locator.t(), has_not_text: String.t() | Regex.t() | Playwright.RegExp.t(), has_text: String.t() | Regex.t() | Playwright.RegExp.t() ] | %{ optional(:has) => Playwright.Locator.t(), optional(:has_not) => Playwright.Locator.t(), optional(:has_not_text) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:has_text) => String.t() | Regex.t() | Playwright.RegExp.t() }
Options of locator/3, see its docs.
@type press_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of press/4, see its docs.
Options of query_selector/3, see its docs.
@type select_option_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of select_option/4, see its docs.
@type set_checked_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of set_checked/4, see its docs.
@type set_content_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of set_content/3, see its docs.
@type set_input_files_options() :: [ no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of set_input_files/4, see its docs.
@type t() :: %Playwright.Frame{ conn: term(), guid: term(), initializer: term(), table: term(), type: term() }
A Frame handle. Compare handles with ==, their fields are internal.
@type tap_options() :: [ force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of tap/3, see its docs.
@type text_content_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of text_content/3, see its docs.
@type type_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of type/4, see its docs.
@type uncheck_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of uncheck/3, see its docs.
@type wait_for_function_options() :: [ polling: number() | :raf, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:polling) => number() | :raf, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_function/4, see its docs.
@type wait_for_load_state_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_load_state/3, see its docs.
@type wait_for_selector_options() :: [ signal: Playwright.AbortSignal.t(), state: :attached | :detached | :visible | :hidden, strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:state) => :attached | :detached | :visible | :hidden, optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of wait_for_selector/3, see its docs.
@type wait_for_url_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of wait_for_url/3, see its docs.
Functions
@spec add_script_tag(t(), add_script_tag_options()) :: {:ok, Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns the added tag when the script's onload fires or when the script content was injected into frame.
Adds a <script> tag into the page with the desired url or content.
Since Playwright 1.8.
Options
:content(String.t/0) - Raw JavaScript content to be injected into frame.:path(String.t/0) - Path to the JavaScript file to be injected into frame. If:pathis a relative path, then it is resolved relative to the current working directory.:type(String.t/0) - Script type. Use 'module' in order to load a JavaScript ES6 module. See script for more details.:url(String.t/0) - URL of a script to be added.
@spec add_script_tag!(t(), add_script_tag_options()) :: Playwright.ElementHandle.t()
Like add_script_tag/2, but returns the value and raises on error.
@spec add_style_tag(t(), add_style_tag_options()) :: {:ok, Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the
content.
Since Playwright 1.8.
Options
:content(String.t/0) - Raw CSS content to be injected into frame.:path(String.t/0) - Path to the CSS file to be injected into frame. If:pathis a relative path, then it is resolved relative to the current working directory.:url(String.t/0) - URL of the<link>tag.
@spec add_style_tag!(t(), add_style_tag_options()) :: Playwright.ElementHandle.t()
Like add_style_tag/2, but returns the value and raises on error.
@spec check(t(), String.t(), check_options()) :: :ok | {:error, Playwright.error()}
This method checks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails. If the element is already checked, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to click in the center of the element. - Ensure that the element is now checked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.check/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - Since Playwright 1.11. A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec check!(t(), String.t(), check_options()) :: :ok
Like check/3, but returns the value and raises on error.
Since Playwright 1.8.
@spec click(t(), String.t(), click_options()) :: :ok | {:error, Playwright.error()}
This method clicks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to click in the center of the element, or the specified:position. - Wait for initiated navigations to either succeed or fail, unless
:no_wait_afteroption is set.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.click/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:button(:left|:right|:middle) - Defaults to:left.:click_count(integer/0) - defaults to 1. SeeUIEvent.detail.:delay(number/0) - Time to wait betweenmousedownandmouseupin milliseconds. Defaults to 0.:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|:meta|:shift) - Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults tofalse.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec click!(t(), String.t(), click_options()) :: :ok
Like click/3, but returns the value and raises on error.
@spec content(t(), content_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Gets the full HTML contents of the frame, including the doctype.
Since Playwright 1.8.
Options
:include_shadow(boolean/0) - Since Playwright 1.64. When true, contents of open shadow roots are included as declarative shadow DOM, i.e.<template shadowrootmode="open">elements nested inside their host elements. Closed shadow roots are never included. Defaults tofalse.
@spec content!(t(), content_options()) :: String.t()
Like content/2, but returns the value and raises on error.
@spec dblclick(t(), String.t(), dblclick_options()) :: :ok | {:error, Playwright.error()}
This method double clicks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to double click in the center of the element, or the specified:position. if the first click of thedblclick()triggers a navigation event, this method will fail.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Note
Playwright.Frame.dblclick/3 dispatches two click events and a single dblclick event.
Discouraged
Use locator-based Playwright.Locator.dblclick/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:button(:left|:right|:middle) - Defaults to:left.:delay(number/0) - Time to wait betweenmousedownandmouseupin milliseconds. Defaults to 0.:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|:meta|:shift) - Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec dblclick!(t(), String.t(), dblclick_options()) :: :ok
Like dblclick/3, but returns the value and raises on error.
@spec dispatch_event( t(), String.t(), String.t(), term() | nil, dispatch_event_options() ) :: :ok | {:error, Playwright.error()}
The snippet below dispatches the click event on the element. Regardless of the visibility state of the element, click
is dispatched. This is equivalent to calling
element.click().
Usage
Frame.dispatch_event!(frame, "button#submit", "click")Under the hood, it creates an instance of an event based on the given type, initializes it with
event_init properties and dispatches it on the element. Events are composed, cancelable and bubble by
default.
Since event_init is event-specific, please refer to the events documentation for the lists of initial
properties:
- DeviceMotionEvent
- DeviceOrientationEvent
- DragEvent
- Event
- FocusEvent
- KeyboardEvent
- MouseEvent
- PointerEvent
- TouchEvent
- WheelEvent
You can also specify JSHandle as the property value if you want live objects to be passed into the event:
# Note you can only create DataTransfer in Chromium and Firefox
data_transfer = Frame.evaluate_handle!(frame, "() => new DataTransfer()")
Frame.dispatch_event!(frame, "#source", "dragstart", %{dataTransfer: data_transfer})Discouraged
Use locator-based Playwright.Locator.dispatch_event/4 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.type- DOM event type:"click","dragstart", etc.event_init- Optional event-specific initialization properties.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 dispatch_event!( t(), String.t(), String.t(), term() | nil, dispatch_event_options() ) :: :ok
Like dispatch_event/5, but returns the value and raises on error.
@spec drag_and_drop(t(), String.t(), String.t(), drag_and_drop_options()) :: :ok | {:error, Playwright.error()}
Since Playwright 1.13.
Arguments
source- A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be used.target- A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:source_position(map/0) - Since Playwright 1.14. Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not specified, some visible point of the element is used.:x:y
:steps(integer/0) - Since Playwright 1.57. Defaults to 1. Sendsninterpolatedmousemoveevents to represent travel between themousedownandmouseupof the drag. When set to 1, emits a singlemousemoveevent at the destination location.:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:target_position(map/0) - Since Playwright 1.14. Drops on the target element at this point relative to the top-left corner of the element's padding box. If not specified, some visible point of the element is used.:x:y
: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.:trial(boolean/0) - When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec drag_and_drop!(t(), String.t(), String.t(), drag_and_drop_options()) :: :ok
Like drag_and_drop/4, but returns the value and raises on error.
@spec eval_on_selector(t(), String.t(), String.t(), term() | nil) :: {:ok, term()} | {:error, Playwright.error()}
Returns the return value of expression.
The method finds an element matching the specified selector within the frame and passes it as a first argument to
expression. If no
elements match the selector, the method fails.
If expression returns a Promise, then Playwright.Frame.eval_on_selector/4 would wait for the promise to resolve and return its
value.
Usage
search_value = Frame.eval_on_selector!(frame, "#search", "el => el.value")
preload_href = Frame.eval_on_selector!(frame, "link[rel=preload]", "el => el.href")
html = Frame.eval_on_selector!(frame, ".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")Discouraged
This method does not wait for the element to pass the actionability
checks and therefore can lead to the flaky tests. Use Playwright.Locator.evaluate/4, other Locator helper methods or web-first assertions instead.
Since Playwright 1.9.
Arguments
selector- A selector to query for.expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Like eval_on_selector/4, but returns the value and raises on error.
@spec eval_on_selector_all(t(), String.t(), String.t(), term() | nil) :: {:ok, term()} | {:error, Playwright.error()}
Returns the return value of expression.
The method finds all elements matching the specified selector within the frame and passes an array of matched elements
as a first argument to expression.
If expression returns a Promise, then Playwright.Frame.eval_on_selector_all/4 would wait for the promise to resolve and return its
value.
Usage
divs_counts = Frame.eval_on_selector_all!(frame, "div", "(divs, min) => divs.length >= min", 10)Discouraged
In most cases, Playwright.Locator.evaluate_all/3,
other Locator helper methods and web-first assertions do a better job.
Since Playwright 1.9.
Arguments
selector- A selector to query for.expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Like eval_on_selector_all/4, but returns the value and raises on error.
@spec evaluate(t(), String.t(), term() | nil, evaluate_options()) :: {:ok, term()} | {:error, Playwright.error()}
Returns the return value of expression.
If the function passed to the Playwright.Frame.evaluate/4 returns a Promise, then Playwright.Frame.evaluate/4 would wait for the promise to
resolve and return its value.
If the function passed to the Playwright.Frame.evaluate/4 returns a non-Serializable value, then
Playwright.Frame.evaluate/4 returns nil. Playwright also supports transferring some
additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.
Usage
result = Frame.evaluate!(frame, "([x, y]) => Promise.resolve(x * y)", [7, 8])
# prints "56"
IO.puts(result)A string can also be passed in instead of a function.
# prints "3"
IO.puts(Frame.evaluate!(frame, "1 + 2"))ElementHandle instances can be passed as an argument to the Playwright.Frame.evaluate/4:
body_handle = Frame.evaluate_handle!(frame, "document.body")
html = Frame.evaluate!(frame, "([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
JSHandle.dispose!(body_handle)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:expose_functions(boolean/0) - Since Playwright 1.62. When set totrue, functions passed insideargare exposed in the page and can be called from the page function. Calling one returns aPromiseof its result. Under the hood, each function is exposed viaPlaywright.Page.expose_function/3, so it is technically accessible from all frames of the page. Exposed functions are cleared upon the top-level navigation. Defaults tofalse, in which case functions are not serializable and passing one fails.
@spec evaluate!(t(), String.t(), term() | nil, evaluate_options()) :: term()
Like evaluate/4, but returns the value and raises on error.
@spec evaluate_handle(t(), String.t(), term() | nil, evaluate_handle_options()) :: {:ok, Playwright.JSHandle.t()} | {:error, Playwright.error()}
Returns the return value of expression as a JSHandle.
The only difference between Playwright.Frame.evaluate/4 and Playwright.Frame.evaluate_handle/4 is that
Playwright.Frame.evaluate_handle/4 returns JSHandle.
If the function, passed to the Playwright.Frame.evaluate_handle/4, returns a Promise, then
Playwright.Frame.evaluate_handle/4 would wait for the promise to resolve and return its value.
Usage
# Handle for the window object
a_window_handle = Frame.evaluate_handle!(frame, "() => Promise.resolve(window)")A string can also be passed in instead of a function.
# Handle for the 'document'.
a_handle = Frame.evaluate_handle!(frame, "document")JSHandle instances can be passed as an argument to the Playwright.Frame.evaluate_handle/4:
a_handle = Frame.evaluate_handle!(frame, "() => document.body")
result_handle = Frame.evaluate_handle!(frame, "([body, suffix]) => body.innerHTML + suffix", [a_handle, "hello"])
IO.puts(JSHandle.json_value!(result_handle))
JSHandle.dispose!(result_handle)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:expose_functions(boolean/0) - Since Playwright 1.62. When set totrue, functions passed insideargare exposed in the page and can be called from the page function. Calling one returns aPromiseof its result. Under the hood, each function is exposed viaPlaywright.Page.expose_function/3, so it is technically accessible from all frames of the page. Exposed functions are cleared upon the top-level navigation. Defaults tofalse, in which case functions are not serializable and passing one fails.
@spec evaluate_handle!(t(), String.t(), term() | nil, evaluate_handle_options()) :: Playwright.JSHandle.t()
Like evaluate_handle/4, but returns the value and raises on error.
@spec fill(t(), String.t(), String.t(), fill_options()) :: :ok | {:error, Playwright.error()}
This method waits for an element matching selector, waits for actionability checks, focuses the element, fills it and triggers an input event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an <input>, <textarea> or [contenteditable] element, this method fails. However, if the element is inside the <label> element that has an associated control, the control will be filled instead.
To send fine-grained keyboard events, use Playwright.Locator.press_sequentially/3.
Discouraged
Use locator-based Playwright.Locator.fill/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.value- Value to fill for the<input>,<textarea>or[contenteditable]element.
Options
:force(boolean/0) - Since Playwright 1.13. Whether to bypass the actionability checks. Defaults tofalse.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 fill!(t(), String.t(), String.t(), fill_options()) :: :ok
Like fill/4, but returns the value and raises on error.
@spec focus(t(), String.t(), focus_options()) :: :ok | {:error, Playwright.error()}
This method fetches an element with selector and focuses it. If there's no element matching
selector, the method waits until a matching element appears in the DOM.
Discouraged
Use locator-based Playwright.Locator.focus/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 focus!(t(), String.t(), focus_options()) :: :ok
Like focus/3, but returns the value and raises on error.
@spec frame_element(t()) :: {:ok, Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns the frame or iframe element handle which corresponds to this frame.
This is an inverse of Playwright.ElementHandle.content_frame/1. Note that returned handle actually belongs to the parent
frame.
This method fails if the frame has been detached before frameElement() returns.
Usage
frame_element = Frame.frame_element!(frame)
content_frame = ElementHandle.content_frame!(frame_element)
# -> true
IO.puts(frame == content_frame)Since Playwright 1.8.
@spec frame_element!(t()) :: Playwright.ElementHandle.t()
Like frame_element/1, but returns the value and raises on error.
@spec frame_locator(t(), String.t() | nil) :: Playwright.FrameLocator.t()
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
When called without selector, the search starts in this frame or in any of the iframes inside it,
so that you don't need to locate each iframe first. Note that the rest of the locator is resolved inside a single
frame, just like any other locator. If it matches elements inside multiple frames, the call fails.
Usage
Following snippet locates element with text "Submit" in the iframe with id my-frame, like <iframe id="my-frame">:
locator = Frame.frame_locator(frame, "#my-iframe") |> FrameLocator.get_by_text("Submit")
Locator.click!(locator)Following snippet locates a button, either in the frame or in one of the iframes inside it:
locator = Frame.frame_locator(frame) |> FrameLocator.get_by_role(:button)
Locator.click!(locator)Since Playwright 1.17.
Arguments
selector- A selector that matches the frame element. When not specified, locator is matched in this frame or in any of the iframes inside it.
@spec get_attribute(t(), String.t(), String.t(), get_attribute_options()) :: {:ok, nil | String.t()} | {:error, Playwright.error()}
Returns element attribute value.
Discouraged
Use locator-based Playwright.Locator.get_attribute/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.name- Attribute name to get the value for.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 get_attribute!(t(), String.t(), String.t(), get_attribute_options()) :: nil | String.t()
Like get_attribute/4, but returns the value and raises on error.
@spec get_by_alt_text( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_alt_text_options() ) :: Playwright.Locator.t()
Allows locating elements by their alt text.
Usage
For example, this method will find the image by alt text "Playwright logo":
<img alt='Playwright logo'>Page.get_by_alt_text(page, "Playwright logo") |> Locator.click!()Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
@spec get_by_label( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_label_options() ) :: Playwright.Locator.t()
Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.
Usage
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
<input aria-label="Username">
<label for="password-input">Password:</label>
<input id="password-input">Page.get_by_label(page, "Username") |> Locator.fill!("john")
Page.get_by_label(page, "Password") |> Locator.fill!("secret")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
@spec get_by_placeholder( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_placeholder_options() ) :: Playwright.Locator.t()
Allows locating input elements by the placeholder text.
Usage
For example, consider the following DOM structure.
<input type="email" placeholder="name@example.com" />You can fill the input after locating it by the placeholder text:
Page.get_by_placeholder(page, "name@example.com") |> Locator.fill!("playwright@microsoft.com")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
@spec get_by_role( t(), :alert | :alertdialog | :application | :article | :banner | :blockquote | :button | :caption | :cell | :checkbox | :code | :columnheader | :combobox | :complementary | :contentinfo | :definition | :deletion | :dialog | :directory | :document | :emphasis | :feed | :figure | :form | :generic | :grid | :gridcell | :group | :heading | :img | :insertion | :link | :list | :listbox | :listitem | :log | :main | :marquee | :math | :meter | :menu | :menubar | :menuitem | :menuitemcheckbox | :menuitemradio | :navigation | :none | :note | :option | :paragraph | :presentation | :progressbar | :radio | :radiogroup | :region | :row | :rowgroup | :rowheader | :scrollbar | :search | :searchbox | :separator | :slider | :spinbutton | :status | :strong | :subscript | :superscript | :switch | :tab | :table | :tablist | :tabpanel | :term | :textbox | :time | :timer | :toolbar | :tooltip | :tree | :treegrid | :treeitem | String.t(), get_by_role_options() ) :: Playwright.Locator.t()
Allows locating elements by their ARIA role, ARIA attributes and accessible name.
Usage
Consider the following DOM structure.
<h3>Sign up</h3>
<label>
<input type="checkbox" /> Subscribe
</label>
<br/>
<button>Submit</button>You can locate each element by its implicit role:
Page.get_by_role(page, :heading, name: "Sign up") |> Expect.to_be_visible!()
Page.get_by_role(page, :checkbox, name: "Subscribe") |> Locator.check!()
Page.get_by_role(page, :button, name: ~r/submit/i) |> Locator.click!()Details
Role selector does not replace accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
Many html elements have an implicitly defined role that is recognized by the role selector. You can find all the supported roles here. ARIA guidelines do not recommend duplicating implicit roles and attributes by setting role and/or aria-* attributes to default values.
Since Playwright 1.27.
Arguments
role- Required aria role.In Elixir, a role is an atom of the typespec (
:button) or a string, also one the typespec lacks ("mark"): the JS client takes any string.
Options
:checked(boolean/0) - An attribute that is usually set byaria-checkedor native<input type=checkbox>controls.Learn more about
aria-checked.:description(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Since Playwright 1.60. Option to match the accessible description. By default, matching is case-insensitive and searches for a substring, use:exactto control this behavior.Learn more about accessible description.
:disabled(boolean/0) - An attribute that is usually set byaria-disabledordisabled.Note
Unlike most other attributes,
disabledis inherited through the DOM hierarchy. Learn more aboutaria-disabled.:exact(boolean/0) - Since Playwright 1.28. Whether:nameand:descriptionare matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when the value is a regular expression. Note that exact match still trims whitespace.:expanded(boolean/0) - An attribute that is usually set byaria-expanded.Learn more about
aria-expanded.:include_hidden(boolean/0) - Option that controls whether hidden elements are matched. By default, only non-hidden elements, as defined by ARIA, are matched by role selector.Learn more about
aria-hidden.:level(integer/0) - A number attribute that is usually present for rolesheading,listitem,row,treeitem, with default values for<h1>-<h6>elements.Learn more about
aria-level.:name(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Option to match the accessible name. By default, matching is case-insensitive and searches for a substring, use:exactto control this behavior.Learn more about accessible name.
:pressed(boolean/0) - An attribute that is usually set byaria-pressed.Learn more about
aria-pressed.:selected(boolean/0) - An attribute that is usually set byaria-selected.Learn more about
aria-selected.
@spec get_by_test_id(t(), String.t() | Regex.t() | Playwright.RegExp.t()) :: Playwright.Locator.t()
Locate element by the test id.
Usage
Consider the following DOM structure.
<button data-testid="directions">Itinéraire</button>You can locate the element by its test id:
Page.get_by_test_id(page, "directions") |> Locator.click!()Details
By default, the data-testid attribute is used as a test id. Use Playwright.Selectors.set_test_id_attribute/2 to configure a different test id attribute if necessary.
# Set a custom test id attribute:
Playwright.selectors(playwright) |> Selectors.set_test_id_attribute("data-pw")Since Playwright 1.27.
Arguments
test_id- Id to locate the element by.
@spec get_by_text( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_text_options() ) :: Playwright.Locator.t()
Allows locating elements that contain given text.
See also Playwright.Locator.filter/2 that allows to match by another criteria, like an accessible role, and then filter by the text content.
Usage
Consider the following DOM structure:
<div>Hello <span>world</span></div>
<div>Hello</div>You can locate by text substring, exact string, or a regular expression:
# Matches <span>
Page.get_by_text(page, "world")
# Matches first <div>
Page.get_by_text(page, "Hello world")
# Matches second <div>
Page.get_by_text(page, "Hello", exact: true)
# Matches both <div>s
Page.get_by_text(page, ~r/Hello/)
# Matches second <div>
Page.get_by_text(page, ~r/^hello$/i)Details
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type button and submit are matched by their value instead of the text content. For example, locating by text "Log in" matches <input type=button value="Log in">.
Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
@spec get_by_title( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_title_options() ) :: Playwright.Locator.t()
Allows locating elements by their title attribute.
Usage
Consider the following DOM structure.
<span title='Issues count'>25 issues</span>You can check the issues count after locating it by the title text:
Page.get_by_title(page, "Issues count") |> Expect.to_have_text!("25 issues")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
@spec goto(t(), String.t(), goto_options()) :: {:ok, nil | Playwright.Response.t()} | {:error, Playwright.error()}
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the last redirect.
The method will fail if:
- there's an SSL error (e.g. in case of self-signed certificates).
- target URL is invalid.
- the
:timeoutis exceeded during navigation. - the remote server does not respond or is unreachable.
- the main resource failed to load.
The method will not fail when any valid HTTP status code is returned by the remote server, including 404
"Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
Playwright.Response.status/1.
Note
The method either fails or returns a main resource response. The only exceptions are navigation to
about:blank or navigation to the same URL with a different hash, which would succeed and return nil.
Note
Headless mode doesn't support navigation to a PDF document. See the upstream issue.
Since Playwright 1.8.
Arguments
url- URL to navigate frame to. The url should include scheme, e.g.https://.
Options
:referer(String.t/0) - Referer header value. If provided it will take preference over the referer header value set byPlaywright.Page.set_extra_http_headers/2.: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 operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec goto!(t(), String.t(), goto_options()) :: nil | Playwright.Response.t()
Like goto/3, but returns the value and raises on error.
@spec hover(t(), String.t(), hover_options()) :: :ok | {:error, Playwright.error()}
This method hovers over an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to hover over the center of the element, or the specified:position.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.hover/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|:meta|:shift) - Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - Since Playwright 1.28. This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec hover!(t(), String.t(), hover_options()) :: :ok
Like hover/3, but returns the value and raises on error.
@spec inner_html(t(), String.t(), inner_html_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns element.innerHTML.
Discouraged
Use locator-based Playwright.Locator.inner_html/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 inner_html!(t(), String.t(), inner_html_options()) :: String.t()
Like inner_html/3, but returns the value and raises on error.
@spec inner_text(t(), String.t(), inner_text_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns element.innerText.
Discouraged
Use locator-based Playwright.Locator.inner_text/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 inner_text!(t(), String.t(), inner_text_options()) :: String.t()
Like inner_text/3, but returns the value and raises on error.
@spec input_value(t(), String.t(), input_value_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns input.value for the selected <input> or <textarea> or <select> element.
Fails for non-input elements. However, if the element is inside the <label> element that has an associated control, returns the value of the control.
Discouraged
Use locator-based Playwright.Locator.input_value/2 instead. Read more about locators.
Since Playwright 1.13.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 input_value!(t(), String.t(), input_value_options()) :: String.t()
Like input_value/3, but returns the value and raises on error.
@spec is_checked(t(), String.t(), is_checked_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is checked. Fails if the element is not a checkbox or radio input.
Discouraged
Use locator-based Playwright.Locator.is_checked/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 is_checked!(t(), String.t(), is_checked_options()) :: boolean()
Like is_checked/3, but returns the value and raises on error.
Returns true if the frame has been detached, or false otherwise.
Since Playwright 1.8.
@spec is_disabled(t(), String.t(), is_disabled_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is disabled, the opposite of enabled.
Discouraged
Use locator-based Playwright.Locator.is_disabled/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 is_disabled!(t(), String.t(), is_disabled_options()) :: boolean()
Like is_disabled/3, but returns the value and raises on error.
@spec is_editable(t(), String.t(), is_editable_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is editable.
Discouraged
Use locator-based Playwright.Locator.is_editable/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 is_editable!(t(), String.t(), is_editable_options()) :: boolean()
Like is_editable/3, but returns the value and raises on error.
@spec is_enabled(t(), String.t(), is_enabled_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is enabled.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 is_enabled!(t(), String.t(), is_enabled_options()) :: boolean()
Like is_enabled/3, but returns the value and raises on error.
@spec is_visible(t(), String.t(), is_visible_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is visible. selector that does not match any elements is considered not visible.
Discouraged
Use locator-based Playwright.Locator.is_visible/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - This option is ignored.Playwright.Frame.is_visible/3does not wait for the element to become visible and returns immediately.
@spec is_visible!(t(), String.t(), is_visible_options()) :: boolean()
Like is_visible/3, but returns the value and raises on error.
@spec locator(t(), String.t(), locator_options()) :: Playwright.Locator.t()
The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
Since Playwright 1.14.
Arguments
selector- A selector to use when resolving DOM element.
Options
:has(Playwright.Locator.t/0) - Narrows down the results of the method to those which contain elements matching this relative locator. For example,articlethat hastext=Playwrightmatches<article><div>Playwright</div></article>.Inner locator must be relative to the outer locator and is queried starting with the outer locator match, not the document root. For example, you can find
contentthat hasdivin<article><content><div>Playwright</div></content></article>. However, looking forcontentthat hasarticle divwill fail, because the inner locator must be relative and should not use any elements outside thecontent.Note that outer and inner locators must belong to the same frame. Inner locator must not contain
FrameLocators.:has_not(Playwright.Locator.t/0) - Since Playwright 1.33. Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the outer one. For example,articlethat does not havedivmatches<article><span>Playwright</span></article>.Note that outer and inner locators must belong to the same frame. Inner locator must not contain
FrameLocators.:has_not_text(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Since Playwright 1.33. Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When passed astring, matching is case-insensitive and searches for a substring.:has_text(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed astring, matching is case-insensitive and searches for a substring. For example,"Playwright"matches<article><div>Playwright</div></article>.
Returns frame's name attribute as specified in the tag.
If the name is empty, returns the id attribute instead.
Note
This value is calculated once when the frame is created, and will not update if the attribute is changed later.
Since Playwright 1.8.
@spec page(t()) :: Playwright.Page.t()
Returns the page containing this frame.
Since Playwright 1.8.
Parent frame, if any. Detached frames and main frames return nil.
Since Playwright 1.8.
@spec press(t(), String.t(), String.t(), press_options()) :: :ok | {:error, Playwright.error()}
key can specify the intended
keyboardEvent.key value or a single character to
generate the text for. A superset of the key values can be found
here. Examples of the keys are:
F1 - F12, Digit0- Digit9, KeyA- KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab,
Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, etc.
Following modification shortcuts are also supported: Shift, Control, Alt, Meta, ShiftLeft, ControlOrMeta.
ControlOrMeta resolves to Control on Windows and Linux and to Meta on macOS.
Holding down Shift will type the text that corresponds to the key in the upper case.
If key is a single character, it is case-sensitive, so the values a and A will generate different
respective texts.
Shortcuts such as key: "Control+o", key: "Control++ or key: "Control+Shift+T" are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.
Discouraged
Use locator-based Playwright.Locator.press/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.key- Name of the key to press or a character to generate, such asArrowLeftora.
Options
:delay(number/0) - Time to wait betweenkeydownandkeyupin milliseconds. Defaults to 0.:no_wait_after(boolean/0) - Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults tofalse.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 press!(t(), String.t(), String.t(), press_options()) :: :ok
Like press/4, but returns the value and raises on error.
@spec query_selector(t(), String.t(), query_selector_options()) :: {:ok, nil | Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns the ElementHandle pointing to the frame element.
Caution
The use of ElementHandle is discouraged, use Locator objects and web-first assertions instead.
The method finds an element matching the specified selector within the frame. If no elements match the selector,
returns nil.
Discouraged
Use locator-based Playwright.Frame.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
Options
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.
@spec query_selector!(t(), String.t(), query_selector_options()) :: nil | Playwright.ElementHandle.t()
Like query_selector/3, but returns the value and raises on error.
@spec query_selector_all(t(), String.t()) :: {:ok, [Playwright.ElementHandle.t()]} | {:error, Playwright.error()}
Returns the ElementHandles pointing to the frame elements.
Caution
The use of ElementHandle is discouraged, use Locator objects instead.
The method finds all elements matching the specified selector within the frame. If no elements match the selector, returns empty array.
Discouraged
Use locator-based Playwright.Frame.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
@spec query_selector_all!(t(), String.t()) :: [Playwright.ElementHandle.t()]
Like query_selector_all/2, but returns the value and raises on error.
@spec select_option( t(), String.t(), :null | String.t() | Playwright.ElementHandle.t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [Playwright.ElementHandle.t()] | [ %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } ], select_option_options() ) :: {:ok, [String.t()]} | {:error, Playwright.error()}
This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.
If the target element is not a <select> element, this method fails. However, if the element is inside the <label> element that has an associated control, the control will be used instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
Usage
# Single selection matching the value or label
Frame.select_option!(frame, "select#colors", "blue")
# single selection matching both the value and the label
Frame.select_option!(frame, "select#colors", %{label: "Blue"})
# multiple selection
Frame.select_option!(frame, "select#colors", ["red", "green", "blue"])Discouraged
Use locator-based Playwright.Locator.select_option/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to query for.values- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.:value- Matches byoption.value. Optional.:label- Matches byoption.label. Optional.:index- Matches by the index. Optional.:valueOrLabel- Matches by value or label, as a string does. Combines such a match withindexin one list.
Options
:force(boolean/0) - Since Playwright 1.13. Whether to bypass the actionability checks. Defaults tofalse.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 select_option!( t(), String.t(), :null | String.t() | Playwright.ElementHandle.t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [Playwright.ElementHandle.t()] | [ %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } ], select_option_options() ) :: [String.t()]
Like select_option/4, but returns the value and raises on error.
@spec set_checked(t(), String.t(), boolean(), set_checked_options()) :: :ok | {:error, Playwright.error()}
This method checks or unchecks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails.
- If the element already has the right checked state, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to click in the center of the element. - Ensure that the element is now checked or unchecked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.set_checked/3 instead. Read more about locators.
Since Playwright 1.15.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.checked- Whether to check or uncheck the checkbox.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec set_checked!(t(), String.t(), boolean(), set_checked_options()) :: :ok
Like set_checked/4, but returns the value and raises on error.
@spec set_content(t(), String.t(), set_content_options()) :: :ok | {:error, Playwright.error()}
This method internally calls document.write(), inheriting all its specific characteristics and behaviors.
Since Playwright 1.8.
Arguments
html- HTML markup to assign to the page.
Options
: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 operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec set_content!(t(), String.t(), set_content_options()) :: :ok
Like set_content/3, but returns the value and raises on error.
@spec set_input_files( t(), String.t(), String.t() | [String.t()] | %{name: String.t(), mimeType: String.t(), buffer: binary()} | [%{name: String.t(), mimeType: String.t(), buffer: binary()}], set_input_files_options() ) :: :ok | {:error, Playwright.error()}
Sets the value of the file input to these file paths or files. 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.
This method expects selector to point to an
input element. However, if the element is inside the <label> element that has an associated control, targets the control instead.
Discouraged
Use locator-based Playwright.Locator.set_input_files/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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_input_files!( t(), String.t(), String.t() | [String.t()] | %{name: String.t(), mimeType: String.t(), buffer: binary()} | [%{name: String.t(), mimeType: String.t(), buffer: binary()}], set_input_files_options() ) :: :ok
Like set_input_files/4, but returns the value and raises on error.
@spec tap(t(), String.t(), tap_options()) :: :ok | {:error, Playwright.error()}
This method taps an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.touchscreen/1to tap the center of the element, or the specified:position.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Note
Playwright.Frame.tap/3 requires that the :has_touch option of the browser context be set to true.
Discouraged
Use locator-based Playwright.Locator.tap/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|:meta|:shift) - Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec tap!(t(), String.t(), tap_options()) :: :ok
Like tap/3, but returns the value and raises on error.
@spec text_content(t(), String.t(), text_content_options()) :: {:ok, nil | String.t()} | {:error, Playwright.error()}
Returns element.textContent.
Discouraged
Use locator-based Playwright.Locator.text_content/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 text_content!(t(), String.t(), text_content_options()) :: nil | String.t()
Like text_content/3, but returns the value and raises on error.
@spec title(t()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns the page title.
Since Playwright 1.8.
Like title/1, but returns the value and raises on error.
@spec type(t(), String.t(), String.t(), type_options()) :: :ok | {:error, Playwright.error()}
Sends a keydown, keypress/input, and keyup event for each character in the text. Playwright.Frame.type/4 can be used to
send fine-grained keyboard events. To fill values in form fields, use Playwright.Frame.fill/4.
To press a special key, like Control or ArrowDown, use Playwright.Keyboard.press/3.
Usage
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.text- A text to type into a focused element.
Options
:delay(number/0) - Time to wait between key presses in milliseconds. Defaults to 0.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 type!(t(), String.t(), String.t(), type_options()) :: :ok
Like type/4, but returns the value and raises on error.
@spec uncheck(t(), String.t(), uncheck_options()) :: :ok | {:error, Playwright.error()}
This method checks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails. If the element is already unchecked, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to click in the center of the element. - Ensure that the element is now unchecked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.uncheck/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - Since Playwright 1.11. A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.: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).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec uncheck!(t(), String.t(), uncheck_options()) :: :ok
Like uncheck/3, but returns the value and raises on error.
Returns frame's url.
Since Playwright 1.8.
@spec wait_for_function(t(), String.t(), term() | nil, wait_for_function_options()) :: {:ok, Playwright.JSHandle.t()} | {:error, Playwright.error()}
Returns when the expression returns a truthy value, returns that value.
Usage
The Playwright.Frame.wait_for_function/4 can be used to observe viewport size change:
# Or Playwright.chromium/1 or Playwright.webkit/1.
browser = Playwright.firefox(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
watch_dog = Task.async(fn -> Page.main_frame(page) |> Frame.wait_for_function!("window.innerWidth < 100") end)
Page.set_viewport_size!(page, %{width: 50, height: 50})
Task.await(watch_dog)
Browser.close!(browser)To pass an argument to the predicate of Playwright.Frame.wait_for_function/4 function:
selector = ".foo"
Frame.wait_for_function!(frame, "selector => !!document.querySelector(selector)", selector)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:polling(number/0|:raf) - If:pollingis:raf, thenexpressionis constantly executed inrequestAnimationFramecallback. If:pollingis a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to:raf.: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 to wait for 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 wait_for_function!(t(), String.t(), term() | nil, wait_for_function_options()) :: Playwright.JSHandle.t()
Like wait_for_function/4, but returns the value and raises on error.
@spec wait_for_load_state( t(), :load | :domcontentloaded | :networkidle | nil, wait_for_load_state_options() ) :: :ok | {:error, Playwright.error()}
Waits for the required load state to be reached.
This returns when the frame reaches a required load state, load by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately.
Note
Most of the time, this method is not needed because Playwright auto-waits before every action.
Usage
# Click triggers navigation.
Frame.click!(frame, "button")
# Waits for 'load' state by default.
Frame.wait_for_load_state!(frame)Since Playwright 1.8.
Arguments
state- Optional load state to wait for, defaults to:load. If the state has been already reached while loading current document, the method resolves immediately. Can be one of::load- wait for theloadevent to be fired.:domcontentloaded- wait for theDOMContentLoadedevent to be fired.:networkidle- DISCOURAGED wait until there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
Options
The options may take the place of state, which is then nil.
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec wait_for_load_state!( t(), :load | :domcontentloaded | :networkidle | nil, wait_for_load_state_options() ) :: :ok
Like wait_for_load_state/3, but returns the value and raises on error.
@spec wait_for_selector(t(), String.t(), wait_for_selector_options()) :: {:ok, nil | Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns when element specified by selector satisfies :state option. Returns nil if waiting for hidden or
detached.
Note
Playwright automatically waits for element to be ready before performing an action. Using
Locator objects and web-first assertions make the code wait-for-selector-free.
Wait for the selector to satisfy :state option (either appear/disappear from dom, or become
visible/hidden). If at the moment of calling the method selector already satisfies the condition, the method
will return immediately. If the selector doesn't satisfy the condition for the :timeout milliseconds, the
function will fail.
Usage
This method works across navigations:
# Or Playwright.firefox/1 or Playwright.webkit/1.
browser = Playwright.chromium(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
for current_url <- ["https://google.com", "https://bbc.com"] do
Page.goto!(page, current_url)
element = Page.main_frame(page) |> Frame.wait_for_selector!("img")
IO.puts("Loaded image: " <> ElementHandle.get_attribute!(element, "src"))
end
Browser.close!(browser)Discouraged
Use web assertions that assert visibility or a locator-based Playwright.Locator.wait_for/2 instead.
Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to query for.
Options
: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).:state(:attached|:detached|:visible|:hidden) - Defaults to:visible. Can be either::attached- wait for element to be present in DOM.:detached- wait for element to not be present in DOM.:visible- wait for element to have non-empty bounding box and novisibility:hidden. Note that element without any content or withdisplay:nonehas an empty bounding box and is not considered visible.:hidden- wait for element to be either detached from DOM, or have an empty bounding box orvisibility:hidden. This is opposite to the:visibleoption.
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.: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 wait_for_selector!(t(), String.t(), wait_for_selector_options()) :: nil | Playwright.ElementHandle.t()
Like wait_for_selector/3, but returns the value and raises on error.
@spec wait_for_timeout(t(), number()) :: :ok | {:error, Playwright.error()}
Waits for the given timeout in milliseconds. It rejects :infinity.
Note that Playwright.Frame.wait_for_timeout/2 should only be used for debugging. Tests using the timer in production are going to
be flaky. Use signals such as network events, selectors becoming visible and others instead.
Discouraged
Never wait for timeout in production. Tests that wait for time are
inherently flaky. Use Locator actions and web assertions that wait automatically.
Since Playwright 1.8.
Arguments
timeout- A timeout to wait for
Like wait_for_timeout/2, but returns the value and raises on error.
@spec wait_for_url( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), wait_for_url_options() ) :: :ok | {:error, Playwright.error()}
Waits for the frame to navigate to the given URL.
Usage
# Clicking the link will indirectly cause a navigation
Frame.click!(frame, "a.delayed-navigation")
Frame.wait_for_url!(frame, "**/target.html")Since Playwright 1.11.
Arguments
url- A glob pattern, regex pattern, URL pattern, or predicate receivingURIto match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec wait_for_url!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), wait_for_url_options() ) :: :ok
Like wait_for_url/3, but returns the value and raises on error.
@spec webmcp(t()) :: Playwright.WebMCP.t()
Tools that the frame registers through the experimental WebMCP browser API. See WebMCP for details.
Since Playwright 1.64.