GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • playwright

This view

  • Original page
  • New address

GeezerVison is showing playwright.hexdocs.pm — Playwright.ElementHandle — playwright v1.49.1-alpha.2

View Source Playwright.ElementHandle (playwright v1.49.1-alpha.2)

ElementHandle represents an in-page DOM element.

ElementHandles can be created with the Playwright.Page.query_selector/3 function, and similar.

⚠️ DISCOURAGED

The use of Playwright.ElementHandle is discouraged; use Playwright.Locator instances and web-first assertions instead.

Example

handle = Page.q(page, "a")
:ok = ElementHandle.click(handle)

ElementHandle prevents DOM elements from garbage collection unless the handle is disposed with Playwright.JSHandle.dispose/1. ElementHandles are auto-disposed when their origin frame is navigated.

An ElementHandle instance can be used as an argument in Playwright.Page.eval_on_selector/5 and Playwright.Page.evaluate/3.

NOTE

In most cases, you would want to use Playwright.Locator instead. You should only use ElementHandle if you want to retain a handle to a particular DOM node that you intend to pass into Playwright.Page.evaluate/3 as an argument.

The difference between Playwright.Locator and ElementHandle is that ElementHandle points to a particular element, while Playwright.Locator captures the logic of how to retrieve an element.

In the example below, handle points to a particular DOM element on the page. If that element changes text or is used by JavaScript to render an entirely different component, handle still points to that very DOM element. This can lead to unexpected behaviors.

handle = Page.q("text=Submit")
ElementHandle.hover(handle)
ElementHandle.click(handle)

With the Playwright.Locator, every time the locator is used, an up-to-date DOM element is located in the page using the selector. So, in the snippet below, the underlying DOM element is going to be located twice.

locator = Page.locator("text=Submit")
Locator.hover(locator)
Locator.click(locator)

Summary

Types

options()

A map/struct providing call options

t()

%Playwright.ElementHandle{}

Functions

bounding_box(handle)
click(handle, options \\ %{})

Clicks on the element, performing the following steps

content_frame(handle)

Returns the Playwright.Frame for element handles referencing iframe nodes, or nil otherwise.

evaluate(handle, expression, arg \\ nil)

See Playwright.JSHandle.evaluate/3.

evaluate_handle(handle, expression, arg \\ nil)

See Playwright.JSHandle.evaluate_handle/3.

get_attribute(handle, name)

Returns the value of an element's attribute.

init(owner, initializer)

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

is_visible(handle)
q(handle, selector)

See Playwright.ElementHandle.query_selector/2.

query_selector(handle, selector)

Searches within an element for a DOM element matching the given selector.

screenshot(handle, options \\ %{})
scroll_into_view(handle, options \\ %{})
select_text(handle, options \\ %{})
string(handle)

See Playwright.JSHandle.string/1.

text_content(handle)

Returns the node.textContent (all text within the element).

Types

Link to this type

options()

View Source
@type options() :: map()

A map/struct providing call options

Link to this type

t()

View Source
@type t() :: %Playwright.ElementHandle{
  guid: term(),
  initializer: term(),
  listeners: term(),
  parent: term(),
  preview: term(),
  session: term(),
  type: term()
}

%Playwright.ElementHandle{}

Functions

Link to this function

bounding_box(handle)

View Source
@spec bounding_box(t()) :: map() | nil
Link to this function

click(handle, options \\ %{})

View Source
@spec click(t(), options()) :: :ok

Clicks on the element, performing the following steps:

  1. Wait for "actionability (guide)" checks on the element, unless force: true option is set.
  2. Scroll the element into view, if needed.
  3. Use Playwright.Page.Mouse to click the center of the element, or the specified option: position.
  4. Wait for initiated navigations to either succeed or fail, unless no_wait_after: true option is set.

If the element is detached from the DOM at any moment during the action, this function raises.

When all steps combined have not finished during the specified :timeout, this function raises a TimeoutError. Passing zero (0) for timeout disables this.

Link to this function

content_frame(handle)

View Source
@spec content_frame(t()) :: Playwright.Frame.t() | nil

Returns the Playwright.Frame for element handles referencing iframe nodes, or nil otherwise.

Link to this function

evaluate(handle, expression, arg \\ nil)

View Source

See Playwright.JSHandle.evaluate/3.

Link to this function

evaluate_handle(handle, expression, arg \\ nil)

View Source

See Playwright.JSHandle.evaluate_handle/3.

Link to this function

get_attribute(handle, name)

View Source
@spec get_attribute(t(), binary()) :: binary() | nil

Returns the value of an element's attribute.

Link to this function

init(owner, initializer)

View Source
@spec init(
  struct(),
  map()
) :: {atom(), struct()}

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

If implemented, the callback will receive:

  1. The newly created "channel owner" struct.
  2. The :initializer received from the Playwright browser server.

The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.

Example

def init(%{session: session} = owner, _initializer) do
  Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
    Logger.warning("Closing #{inspect(event.target)}")
  end)

  {:ok, %{owner | version: "1.2.3"}}
end

Returns

  • {:ok, struct()}

Arguments

key/nametypedescription
ownerparamstruct()The newly created channel owner (resource).
initializerparamstruct()The initializer received from with the channel owner instance was derived.
Link to this function

is_visible(handle)

View Source
@spec is_visible(t()) :: boolean()
Link to this function

q(handle, selector)

View Source

See Playwright.ElementHandle.query_selector/2.

Link to this function

query_selector(handle, selector)

View Source
@spec query_selector(t(), binary()) :: t() | nil

Searches within an element for a DOM element matching the given selector.

Finds an element matching the specified selector within the subtree of the ElementHandle. See "working with selectors (guide)" for more details.

If no elements match the selector, returns nil.

Link to this function

screenshot(handle, options \\ %{})

View Source
@spec screenshot(t(), options()) :: binary()
Link to this function

scroll_into_view(handle, options \\ %{})

View Source
@spec scroll_into_view(t(), options()) :: :ok
Link to this function

select_text(handle, options \\ %{})

View Source
@spec select_text(t(), options()) :: :ok
Link to this function

string(handle)

View Source

See Playwright.JSHandle.string/1.

Link to this function

text_content(handle)

View Source
@spec text_content(t()) :: binary() | nil

Returns the node.textContent (all text within the element).

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.