- extends:
JSHandle
ElementHandle represents an in-page DOM element. ElementHandles can be created with the Playwright.Page.query_selector/3 method.
Discouraged
The use of ElementHandle is discouraged, use Locator objects and web-first assertions instead.
href_element = Page.query_selector!(page, "a")
ElementHandle.click!(href_element)ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
Playwright.JSHandle.dispose/1. ElementHandles are auto-disposed when their origin frame gets navigated.
ElementHandle instances can be used as an argument in Playwright.Page.eval_on_selector/4 and Playwright.Page.evaluate/4 methods.
The difference between the Locator and ElementHandle is that the ElementHandle points to a particular element, while Locator captures the logic of how to retrieve an element.
In the example below, handle points to a particular DOM element on page. If that element changes text or is used by React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to unexpected behaviors.
handle = Page.query_selector!(page, "text=Submit")
# ...
ElementHandle.hover!(handle)
ElementHandle.click!(handle)With the locator, every time the element is used, up-to-date DOM element is located in the page using the selector. So in the snippet below, underlying DOM element is going to be located twice.
locator = Page.get_by_text(page, "Submit")
# ...
Locator.hover!(locator)
Locator.click!(locator)Since Playwright 1.8.
Extends Playwright.JSHandle: its functions take this handle too.
The examples alias the modules they use (alias Playwright.{Locator, Page}).
Summary
Types
Options of check/2, see its docs.
Options of click/2, see its docs.
Options of dblclick/2, see its docs.
Options of fill/3, see its docs.
Options of hover/2, see its docs.
Options of press/3, see its docs.
Options of screenshot/2, see its docs.
Options of scroll_into_view_if_needed/2, see its docs.
Options of select_option/3, see its docs.
Options of select_text/2, see its docs.
Options of set_checked/3, see its docs.
Options of set_input_files/3, see its docs.
A ElementHandle handle. Compare handles with ==, their fields are internal.
Options of tap/2, see its docs.
Options of type/3, see its docs.
Options of uncheck/2, see its docs.
Options of wait_for_element_state/3, see its docs.
Options of wait_for_selector/3, see its docs.
Functions
This method returns the bounding box of the element, or nil if the element is not visible. The bounding box is
calculated relative to the main frame viewport - which is usually the same as the browser window.
Like bounding_box/1, but returns the value and raises on error.
This method checks the element by performing the following steps
Like check/2, but returns the value and raises on error.
This method clicks the element by performing the following steps
Like click/2, but returns the value and raises on error.
Returns the content frame for element handles referencing iframe nodes, or nil otherwise
Like content_frame/1, but returns the value and raises on error.
This method double clicks the element by performing the following steps
Like dblclick/2, 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/3, 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.
This method 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/3, but returns the value and raises on error.
Calls focus on the element.
Like focus/1, but returns the value and raises on error.
Returns element attribute value.
Like get_attribute/2, but returns the value and raises on error.
This method hovers over the element by performing the following steps
Like hover/2, but returns the value and raises on error.
Returns the element.innerHTML.
Like inner_html/1, but returns the value and raises on error.
Returns the element.innerText.
Like inner_text/1, but returns the value and raises on error.
Returns input.value for the selected <input> or <textarea> or <select> element.
Like input_value/1, 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/1, but returns the value and raises on error.
Returns whether the element is disabled, the opposite of enabled.
Like is_disabled/1, but returns the value and raises on error.
Returns whether the element is editable.
Like is_editable/1, but returns the value and raises on error.
Returns whether the element is enabled.
Like is_enabled/1, but returns the value and raises on error.
Returns whether the element is hidden, the opposite of visible.
Like is_hidden/1, but returns the value and raises on error.
Returns whether the element is visible.
Like is_visible/1, but returns the value and raises on error.
Returns the frame containing the given element.
Like owner_frame/1, but returns the value and raises on error.
Focuses the element, and then uses Playwright.Keyboard.down/2 and Playwright.Keyboard.up/2.
Like press/3, but returns the value and raises on error.
The method finds an element matching the specified selector in the ElementHandle's subtree. If no elements match the selector,
returns nil.
Like query_selector/2, but returns the value and raises on error.
The method finds all elements matching the specified selector in the ElementHandles subtree. If no elements match the selector,
returns empty array.
Like query_selector_all/2, but returns the value and raises on error.
This method captures a screenshot of the page, clipped to the size and position of this particular element. If the element is covered by other elements, it will not be actually visible on the screenshot. If the element is a scrollable container, only the currently scrolled content will be visible on the screenshot.
Like screenshot/2, but returns the value and raises on error.
This method waits for actionability checks, then tries to scroll element into view, unless it is
completely visible as defined by
IntersectionObserver's ratio.
Like scroll_into_view_if_needed/2, but returns the value and raises on error.
This method waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.
Like select_option/3, but returns the value and raises on error.
This method waits for actionability checks, then focuses the element and selects all its text content.
Like select_text/2, but returns the value and raises on error.
This method checks or unchecks an element by performing the following steps
Like set_checked/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.
For inputs with a [webkitdirectory] attribute, only a single directory path is supported.
Like set_input_files/3, but returns the value and raises on error.
This method taps the element by performing the following steps
Like tap/2, but returns the value and raises on error.
Returns the node.textContent.
Like text_content/1, but returns the value and raises on error.
Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.
Like type/3, but returns the value and raises on error.
This method checks the element by performing the following steps
Like uncheck/2, but returns the value and raises on error.
Returns when the element satisfies the state.
Like wait_for_element_state/3, but returns the value and raises on error.
Returns element specified by selector when it satisfies :state option. Returns nil if waiting for hidden
or detached.
Like wait_for_selector/3, but returns the value and raises on error.
Types
@type check_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), 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(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of check/2, 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(), steps: integer(), 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(:steps) => integer(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of click/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(), steps: integer(), 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(:steps) => integer(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of dblclick/2, see its docs.
@type fill_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of fill/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(), 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(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of hover/2, see its docs.
@type press_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of press/3, see its docs.
@type screenshot_options() :: [ animations: :disabled | :allow, caret: :hide | :initial, mask: [Playwright.Locator.t()], mask_color: String.t(), omit_background: boolean(), path: String.t(), quality: integer(), scale: :css | :device, signal: Playwright.AbortSignal.t(), style: String.t(), timeout: number() | :infinity, type: :png | :jpeg | :webp ] | %{ optional(:animations) => :disabled | :allow, optional(:caret) => :hide | :initial, optional(:mask) => [Playwright.Locator.t()], optional(:mask_color) => String.t(), optional(:omit_background) => boolean(), optional(:path) => String.t(), optional(:quality) => integer(), optional(:scale) => :css | :device, optional(:signal) => Playwright.AbortSignal.t(), optional(:style) => String.t(), optional(:timeout) => number() | :infinity, optional(:type) => :png | :jpeg | :webp }
Options of screenshot/2, see its docs.
@type scroll_into_view_if_needed_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of scroll_into_view_if_needed/2, see its docs.
@type select_option_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of select_option/3, see its docs.
@type select_text_options() :: [ force: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of select_text/2, 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(), 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(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of set_checked/3, see its docs.
@type set_input_files_options() :: [ no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of set_input_files/3, see its docs.
@type t() :: %Playwright.ElementHandle{ conn: term(), guid: term(), initializer: term(), table: term(), type: term() }
A ElementHandle 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(), 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(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of tap/2, see its docs.
@type type_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of type/3, see its docs.
@type uncheck_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), 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(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of uncheck/2, see its docs.
@type wait_for_element_state_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_element_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.
Functions
@spec bounding_box(t()) :: {:ok, nil | %{x: number(), y: number(), width: number(), height: number()}} | {:error, Playwright.error()}
This method returns the bounding box of the element, or nil if the element is not visible. The bounding box is
calculated relative to the main frame viewport - which is usually the same as the browser window.
Scrolling affects the returned bounding box, similarly to
Element.getBoundingClientRect. That
means x and/or y may be negative.
Elements from child frames return the bounding box relative to the main frame, unlike the Element.getBoundingClientRect.
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following snippet should click the center of the element.
Usage
box = ElementHandle.bounding_box!(element_handle)
Mouse.click!(Page.mouse(page), box.x + box.width / 2, box.y + box.height / 2)Since Playwright 1.8.
Like bounding_box/1, but returns the value and raises on error.
@spec check(t(), check_options()) :: :ok | {:error, Playwright.error()}
This method checks the element by performing the following steps:
- Ensure that 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 element, unless
:forceoption is set. - 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.
If the element is detached from the DOM at any moment during the action, 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.
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).: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(), check_options()) :: :ok
Like check/2, but returns the value and raises on error.
@spec click(t(), click_options()) :: :ok | {:error, Playwright.error()}
This method clicks the element by performing the following steps:
- Wait for actionability checks on the element, unless
:forceoption is set. - 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.
If the element is detached from the DOM at any moment during the action, 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.click/2 instead. Read more about locators.
Since Playwright 1.8.
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).:steps(integer/0) - Since Playwright 1.57. Defaults to 1. Sendsninterpolatedmousemoveevents to represent travel between Playwright's current cursor position and the provided destination. When set to 1, emits a singlemousemoveevent at the destination location.: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 click!(t(), click_options()) :: :ok
Like click/2, but returns the value and raises on error.
@spec content_frame(t()) :: {:ok, nil | Playwright.Frame.t()} | {:error, Playwright.error()}
Returns the content frame for element handles referencing iframe nodes, or nil otherwise
Since Playwright 1.8.
@spec content_frame!(t()) :: nil | Playwright.Frame.t()
Like content_frame/1, but returns the value and raises on error.
@spec dblclick(t(), dblclick_options()) :: :ok | {:error, Playwright.error()}
This method double clicks the element by performing the following steps:
- Wait for actionability checks on the element, unless
:forceoption is set. - 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 element is detached from the DOM at any moment during the action, 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.
Note
Playwright.ElementHandle.dblclick/2 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.
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).:steps(integer/0) - Since Playwright 1.57. Defaults to 1. Sendsninterpolatedmousemoveevents to represent travel between Playwright's current cursor position and the provided destination. When set to 1, emits a singlemousemoveevent at the destination location.: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 dblclick!(t(), dblclick_options()) :: :ok
Like dblclick/2, but returns the value and raises on error.
@spec dispatch_event(t(), String.t(), term() | nil) :: :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
ElementHandle.dispatch_event!(element_handle, "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 = Page.evaluate_handle!(page, "() => new DataTransfer()")
ElementHandle.dispatch_event!(element_handle, "dragstart", %{dataTransfer: data_transfer})Discouraged
Use locator-based Playwright.Locator.dispatch_event/4 instead. Read more about locators.
Since Playwright 1.8.
Arguments
type- DOM event type:"click","dragstart", etc.event_init- Optional event-specific initialization properties.
Like dispatch_event/3, 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 in the ElementHandles subtree 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.ElementHandle.eval_on_selector/4 would wait for the promise to resolve and return its
value.
Usage
tweet_handle = Page.query_selector!(page, ".tweet")
assert ElementHandle.eval_on_selector!(tweet_handle, ".like", "node => node.innerText") == "100"
assert ElementHandle.eval_on_selector!(tweet_handle, ".retweets", "node => node.innerText") == "10"Discouraged
This method does not wait for the element to pass 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 in the ElementHandle's subtree and passes an array of
matched elements as a first argument to expression.
If expression returns a Promise, then Playwright.ElementHandle.eval_on_selector_all/4 would wait for the promise to resolve and return its
value.
Usage
<div class="feed">
<div class="tweet">Hello!</div>
<div class="tweet">Hi!</div>
</div>feed_handle = Page.query_selector!(page, ".feed")
assert ElementHandle.eval_on_selector_all!(feed_handle, ".tweet", "nodes => nodes.map(n => n.innerText)") ==
["Hello!", "Hi!"]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 fill(t(), String.t(), fill_options()) :: :ok | {:error, Playwright.error()}
This method 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
value- Value to set 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).: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(), fill_options()) :: :ok
Like fill/3, but returns the value and raises on error.
@spec focus(t()) :: :ok | {:error, Playwright.error()}
Calls focus on the element.
Discouraged
Use locator-based Playwright.Locator.focus/2 instead. Read more about locators.
Since Playwright 1.8.
@spec focus!(t()) :: :ok
Like focus/1, but returns the value and raises on error.
@spec get_attribute(t(), String.t()) :: {: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
name- Attribute name to get the value for.
Like get_attribute/2, but returns the value and raises on error.
@spec hover(t(), hover_options()) :: :ok | {:error, Playwright.error()}
This method hovers over the element by performing the following steps:
- Wait for actionability checks on the element, unless
:forceoption is set. - Scroll the element into view if needed.
- Use
Playwright.Page.mouse/1to hover over the center of the element, or the specified:position.
If the element is detached from the DOM at any moment during the action, 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.hover/2 instead. Read more about locators.
Since Playwright 1.8.
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).: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 hover!(t(), hover_options()) :: :ok
Like hover/2, but returns the value and raises on error.
@spec inner_html(t()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns the element.innerHTML.
Discouraged
Use locator-based Playwright.Locator.inner_html/2 instead. Read more about locators.
Since Playwright 1.8.
Like inner_html/1, but returns the value and raises on error.
@spec inner_text(t()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns the element.innerText.
Discouraged
Use locator-based Playwright.Locator.inner_text/2 instead. Read more about locators.
Since Playwright 1.8.
Like inner_text/1, but returns the value and raises on error.
@spec input_value(t()) :: {: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.
Like input_value/1, but returns the value and raises on error.
@spec is_checked(t()) :: {: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.
Like is_checked/1, but returns the value and raises on error.
@spec is_disabled(t()) :: {: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.
Like is_disabled/1, but returns the value and raises on error.
@spec is_editable(t()) :: {: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.
Like is_editable/1, but returns the value and raises on error.
@spec is_enabled(t()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is enabled.
Discouraged
Use locator-based Playwright.Locator.is_enabled/2 instead. Read more about locators.
Since Playwright 1.8.
Like is_enabled/1, but returns the value and raises on error.
@spec is_visible(t()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is visible.
Discouraged
Use locator-based Playwright.Locator.is_visible/2 instead. Read more about locators.
Since Playwright 1.8.
Like is_visible/1, but returns the value and raises on error.
@spec owner_frame(t()) :: {:ok, nil | Playwright.Frame.t()} | {:error, Playwright.error()}
Returns the frame containing the given element.
Since Playwright 1.8.
@spec owner_frame!(t()) :: nil | Playwright.Frame.t()
Like owner_frame/1, but returns the value and raises on error.
@spec press(t(), String.t(), press_options()) :: :ok | {:error, Playwright.error()}
Focuses the element, and then uses Playwright.Keyboard.down/2 and Playwright.Keyboard.up/2.
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.
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
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).: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(), press_options()) :: :ok
Like press/3, but returns the value and raises on error.
@spec query_selector(t(), String.t()) :: {:ok, nil | t()} | {:error, Playwright.error()}
The method finds an element matching the specified selector in the ElementHandle's subtree. If no elements match the selector,
returns nil.
Discouraged
Use locator-based Playwright.Page.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
Like query_selector/2, but returns the value and raises on error.
@spec query_selector_all(t(), String.t()) :: {:ok, [t()]} | {:error, Playwright.error()}
The method finds all elements matching the specified selector in the ElementHandles subtree. If no elements match the selector,
returns empty array.
Discouraged
Use locator-based Playwright.Page.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
Like query_selector_all/2, but returns the value and raises on error.
@spec screenshot(t(), screenshot_options()) :: {:ok, binary()} | {:error, Playwright.error()}
This method captures a screenshot of the page, clipped to the size and position of this particular element. If the element is covered by other elements, it will not be actually visible on the screenshot. If the element is a scrollable container, only the currently scrolled content will be visible on the screenshot.
This method waits for the actionability checks, then scrolls element into view before taking a screenshot. If the element is detached from DOM, the method fails.
Returns the buffer with the captured screenshot.
Discouraged
Use locator-based Playwright.Locator.screenshot/2 instead. Read more about locators.
Since Playwright 1.8.
Options
:animations(:disabled|:allow) - When set to:disabled, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:- finite animations are fast-forwarded to completion, so they'll fire
transitionendevent. - infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to
:allowthat leaves animations untouched.- finite animations are fast-forwarded to completion, so they'll fire
:caret(:hide|:initial) - When set to:hide, screenshot will hide text caret. When set to:initial, text caret behavior will not be changed. Defaults to:hide.:mask(list ofPlaywright.Locator.t/0) - Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box#FF00FF(customized by:mask_color) that completely covers its bounding box. The mask is also applied to invisible elements, see Matching only visible elements to disable that.:mask_color(String.t/0) - Since Playwright 1.35. Specify the color of the overlay box for masked elements, in CSS color format. Default color is pink#FF00FF.:omit_background(boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable tojpegimages. Defaults tofalse.:path(String.t/0) - The file path to save the image to. The screenshot type will be inferred from file extension. If:pathis a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.:quality(integer/0) - The quality of the image, between 0-100. Not applicable topngimages. Forjpegthe default is80. Forwebp, a quality of100(the default) produces a lossless image, while lower values use lossy compression.:scale(:css|:device) - When set to:css, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using:deviceoption will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.Defaults to
:device.: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).:style(String.t/0) - Since Playwright 1.41. Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.: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.:type(:png|:jpeg|:webp) - Specify screenshot type, defaults to:png.
@spec screenshot!(t(), screenshot_options()) :: binary()
Like screenshot/2, but returns the value and raises on error.
@spec scroll_into_view_if_needed(t(), scroll_into_view_if_needed_options()) :: :ok | {:error, Playwright.error()}
This method waits for actionability checks, then tries to scroll element into view, unless it is
completely visible as defined by
IntersectionObserver's ratio.
Fails when element_handle does not point to an element
connected to a Document or a ShadowRoot.
See scrolling for alternative ways to scroll.
Discouraged
Use locator-based Playwright.Locator.scroll_into_view_if_needed/2 instead. Read more about locators.
Since Playwright 1.8.
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 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 scroll_into_view_if_needed!(t(), scroll_into_view_if_needed_options()) :: :ok
Like scroll_into_view_if_needed/2, but returns the value and raises on error.
@spec select_option( t(), :null | String.t() | t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [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 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
ElementHandle.select_option!(handle, "blue")
# single selection matching the label
ElementHandle.select_option!(handle, %{label: "Blue"})
# multiple selection
ElementHandle.select_option!(handle, ["red", "green", "blue"])Discouraged
Use locator-based Playwright.Locator.select_option/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
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).: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(), :null | String.t() | t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [t()] | [ %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } ], select_option_options() ) :: [String.t()]
Like select_option/3, but returns the value and raises on error.
@spec select_text(t(), select_text_options()) :: :ok | {:error, Playwright.error()}
This method waits for actionability checks, then focuses the element and selects all its text content.
If the element is inside the <label> element that has an associated control, focuses and selects text in the control instead.
Discouraged
Use locator-based Playwright.Locator.select_text/2 instead. Read more about locators.
Since Playwright 1.8.
Options
:force(boolean/0) - Since Playwright 1.13. Whether to bypass the actionability checks. 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).: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_text!(t(), select_text_options()) :: :ok
Like select_text/2, but returns the value and raises on error.
@spec set_checked(t(), boolean(), set_checked_options()) :: :ok | {:error, Playwright.error()}
This method checks or unchecks an element by performing the following steps:
- Ensure that 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
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).: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(), boolean(), set_checked_options()) :: :ok
Like set_checked/3, but returns the value and raises on error.
@spec set_input_files( 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.
For inputs with a [webkitdirectory] attribute, only a single directory path is supported.
This method expects ElementHandle 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
files:name- File name:mimeType- File type:buffer- File content
Options
:no_wait_after(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec set_input_files!( 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/3, but returns the value and raises on error.
@spec tap(t(), tap_options()) :: :ok | {:error, Playwright.error()}
This method taps the element by performing the following steps:
- Wait for actionability checks on the element, unless
:forceoption is set. - Scroll the element into view if needed.
- Use
Playwright.Page.touchscreen/1to tap the center of the element, or the specified:position.
If the element is detached from the DOM at any moment during the action, 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.
Note
Playwright.ElementHandle.tap/2 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.
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).: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 tap!(t(), tap_options()) :: :ok
Like tap/2, but returns the value and raises on error.
@spec text_content(t()) :: {:ok, nil | String.t()} | {:error, Playwright.error()}
Returns the node.textContent.
Discouraged
Use locator-based Playwright.Locator.text_content/2 instead. Read more about locators.
Since Playwright 1.8.
Like text_content/1, but returns the value and raises on error.
@spec type(t(), String.t(), type_options()) :: :ok | {:error, Playwright.error()}
Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.
To press a special key, like Control or ArrowDown, use Playwright.ElementHandle.press/3.
Usage
Since Playwright 1.8.
Arguments
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).: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(), type_options()) :: :ok
Like type/3, but returns the value and raises on error.
@spec uncheck(t(), uncheck_options()) :: :ok | {:error, Playwright.error()}
This method checks the element by performing the following steps:
- Ensure that 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 element, unless
:forceoption is set. - 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.
If the element is detached from the DOM at any moment during the action, 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.
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).: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(), uncheck_options()) :: :ok
Like uncheck/2, but returns the value and raises on error.
@spec wait_for_element_state( t(), :visible | :hidden | :stable | :enabled | :disabled | :editable, wait_for_element_state_options() ) :: :ok | {:error, Playwright.error()}
Returns when the element satisfies the state.
Depending on the state parameter, this method waits for one of the actionability checks
to pass. This method fails when the element is detached while waiting, unless waiting for the :hidden state.
:visibleWait until the element is visible.:hiddenWait until the element is not visible or not attached. Note that waiting for hidden does not fail when the element detaches.:stableWait until the element is both visible and stable.:enabledWait until the element is enabled.:disabledWait until the element is not enabled.:editableWait until the element is editable.
If the element does not satisfy the condition for the :timeout milliseconds, this method will fail.
Since Playwright 1.8.
Arguments
state- A state to wait for, see below for more details.
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 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_element_state!( t(), :visible | :hidden | :stable | :enabled | :disabled | :editable, wait_for_element_state_options() ) :: :ok
Like wait_for_element_state/3, but returns the value and raises on error.
@spec wait_for_selector(t(), String.t(), wait_for_selector_options()) :: {:ok, nil | t()} | {:error, Playwright.error()}
Returns element specified by selector when it satisfies :state option. Returns nil if waiting for hidden
or detached.
Wait for the selector relative to the element handle 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
Page.set_content!(page, "<div><span></span></div>")
div = Page.query_selector!(page, "div")
# Waiting for the 'span' selector relative to the div.
span = ElementHandle.wait_for_selector!(div, "span", state: :attached)Note
This method does not work across navigations, use Playwright.Page.wait_for_selector/3 instead.
Discouraged
Use web assertions that assert visibility or a locator-based Playwright.Locator.wait_for/2 instead.
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.15. 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 | t()
Like wait_for_selector/3, but returns the value and raises on error.