class Playwright::ElementHandle

“‘
locator.click()
locator.hover()
locator = page.get_by_text(“Submit”)
“`python sync
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.
“`
handle.click()
handle.hover()
handle = page.query_selector(“text=Submit”)
“`python sync
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.
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.
ElementHandle instances can be used as an argument in [`method: Page.evalOnSelector`] and [`method: Page.evaluate`] methods.
[`method: JSHandle.dispose`]. ElementHandles are auto-disposed when their origin frame gets navigated.
ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
“`
href_element.click()
href_element = page.query_selector(“a”)
“`python sync
NOTE: The use of ElementHandle is discouraged, use `Locator` objects and web-first assertions instead.
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [`method: Page.querySelector`] method.
- extends: `JSHandle`

def bounding_box

```
page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
box = element_handle.bounding_box()
```python sync

**Usage**

snippet should click the center of the element.
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following

[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
Elements from child frames return the bounding box relative to the main frame, unlike the

means `x` and/or `y` may be negative.
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
Scrolling affects the returned bounding box, similarly to

calculated relative to the main frame viewport - which is usually the same as the browser window.
This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
def bounding_box
  wrap_impl(@impl.bounding_box)
end

def check(

`TimeoutError`. Passing zero timeout disables this.
When all steps combined have not finished during the specified `timeout`, this method throws a

If the element is detached from the DOM at any moment during the action, this method throws.

1. Ensure that the element is now checked. If not, this method throws.
1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1. Use [`property: Page.mouse`] to click in the center of the element.
1. Scroll the element into view if needed.
1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
This method checks the element by performing the following steps:
def check(
      force: nil,
      noWaitAfter: nil,
      position: nil,
      timeout: nil,
      trial: nil)
  wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
end

def checked?

Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
def checked?
  wrap_impl(@impl.checked?)
end

def click(

`TimeoutError`. Passing zero timeout disables this.
When all steps combined have not finished during the specified `timeout`, this method throws a

If the element is detached from the DOM at any moment during the action, this method throws.

1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
1. Scroll the element into view if needed.
1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
This method clicks the element by performing the following steps:
def click(
      button: nil,
      clickCount: nil,
      delay: nil,
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      timeout: nil,
      trial: nil)
  wrap_impl(@impl.click(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
end

def content_frame

Returns the content frame for element handles referencing iframe nodes, or `null` otherwise
def content_frame
  wrap_impl(@impl.content_frame)
end

def dblclick(

**NOTE**: `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event.

`TimeoutError`. Passing zero timeout disables this.
When all steps combined have not finished during the specified `timeout`, this method throws a

If the element is detached from the DOM at any moment during the action, this method throws.

1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the first click of the `dblclick()` triggers a navigation event, this method will throw.
1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
1. Scroll the element into view if needed.
1. Wait for [actionability](../actionability.md) checks on the element, unless `force` option is set.
This method double clicks the element by performing the following steps:
def dblclick(
      button: nil,
      delay: nil,
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      timeout: nil,
      trial: nil)
  wrap_impl(@impl.dblclick(button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
end

def disabled?

Returns whether the element is disabled, the opposite of [enabled](../actionability.md#enabled).
def disabled?
  wrap_impl(@impl.disabled?)
end

def dispatch_event(type, eventInit: nil)

```
element_handle.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
data_transfer = page.evaluate_handle("new DataTransfer()")
# note you can only create data_transfer in chromium and firefox
```python sync

You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:

- [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
- [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
- [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
properties:
Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial

default.
`eventInit` properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
Under the hood, it creates an instance of an event based on the given `type`, initializes it with

```
element_handle.dispatch_event("click")
```python sync

**Usage**

[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
is dispatched. This is equivalent to calling
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, `click`
def dispatch_event(type, eventInit: nil)
  wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit)))
end

def editable?

Returns whether the element is [editable](../actionability.md#editable).
def editable?
  wrap_impl(@impl.editable?)
end

def enabled?

Returns whether the element is [enabled](../actionability.md#enabled).
def enabled?
  wrap_impl(@impl.enabled?)
end

def eval_on_selector(selector, expression, arg: nil)

```
assert tweet_handle.eval_on_selector(".retweets", "node => node.innerText") == "10"
assert tweet_handle.eval_on_selector(".like", "node => node.innerText") == "100"
tweet_handle = page.query_selector(".tweet")
```python sync

**Usage**

value.
If `expression` returns a [Promise], then [`method: ElementHandle.evalOnSelector`] would wait for the promise to resolve and return its

argument to `expression`. If no elements match the selector, the method throws an error.
The method finds an element matching the specified selector in the `ElementHandle`s subtree and passes it as a first

Returns the return value of `expression`.
def eval_on_selector(selector, expression, arg: nil)
  wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
end

def eval_on_selector_all(selector, expression, arg: nil)

```
assert feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") == ["hello!", "hi!"]
feed_handle = page.query_selector(".feed")
```python sync

```

Hi!

Hello!


```html

**Usage**

value.
If `expression` returns a [Promise], then [`method: ElementHandle.evalOnSelectorAll`] would wait for the promise to resolve and return its

matched elements as a first argument to `expression`.
The method finds all elements matching the specified selector in the `ElementHandle`'s subtree and passes an array of

Returns the return value of `expression`.
def eval_on_selector_all(selector, expression, arg: nil)
  wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
end

def event_emitter_proxy

def event_emitter_proxy
_emitter_proxy ||= EventEmitterProxy.new(self, @impl)

def fill(value, force: nil, noWaitAfter: nil, timeout: nil)

To send fine-grained keyboard events, use [`method: Locator.pressSequentially`].

If the target element is not an ``, `