# class: ElementHandle
* extends: [JSHandle]
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [`method: Page.$`] method.
```js
const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const hrefElement = await page.$('a');
await hrefElement.click();
// ...
})();
```
ElementHandle prevents DOM element from garbage collection unless the handle is disposed with [`method:
JSHandle.dispose`]. ElementHandles are auto-disposed when their origin frame gets navigated.
ElementHandle instances can be used as an argument in [`method: Page.$eval`] and [`method: Page.evaluate`] methods.
## async method: ElementHandle.$
* langs:
- alias-python: query_selector
- returns: <[null]|[ElementHandle]>
The method finds an element matching the specified selector in the `ElementHandle`'s subtree. See [Working with
selectors](./selectors.md#working-with-selectors) for more details. If no elements match the selector, returns `null`.
### param: ElementHandle.$.selector = %%-query-selector-%%
## async method: ElementHandle.$$
* langs:
- alias-python: query_selector_all
- returns: <[Array]<[ElementHandle]>>
The method finds all elements matching the specified selector in the `ElementHandle`s subtree. See [Working with
selectors](./selectors.md#working-with-selectors) for more details. If no elements match the selector, returns empty array.
### param: ElementHandle.$$.selector = %%-query-selector-%%
## async method: ElementHandle.$eval
* langs:
- alias-python: eval_on_selector
- returns: <[Serializable]>
Returns the return value of [`param: pageFunction`]
The method finds an element matching the specified selector in the `ElementHandle`s subtree and passes it as a first
argument to [`param: pageFunction`]. See [Working with selectors](./selectors.md#working-with-selectors) for more details. If no
elements match the selector, the method throws an error.
If [`param: pageFunction`] returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return
its value.
Examples:
```js
const tweetHandle = await page.$('.tweet');
expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe('100');
expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
```
### param: ElementHandle.$eval.selector = %%-query-selector-%%
### param: ElementHandle.$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Element]\)>
Function to be evaluated in browser context
### param: ElementHandle.$eval.arg
- `arg` <[EvaluationArgument]>
Optional argument to pass to [`param: pageFunction`]
## async method: ElementHandle.$$eval
* langs:
- alias-python: eval_on_selector_all
- returns: <[Serializable]>
Returns the return value of [`param: pageFunction`]
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 [`param: pageFunction`]. See [Working with selectors](./selectors.md#working-with-selectors)
for more details.
If [`param: pageFunction`] returns a [Promise], then `frame.$$eval` would wait for the promise to resolve and return
its value.
Examples:
```html
Hello!
Hi!
```
```js
const feedHandle = await page.$('.feed');
expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).toEqual(['Hello!', 'Hi!']);
```
### param: ElementHandle.$$eval.selector = %%-query-selector-%%
### param: ElementHandle.$$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Array]<[Element]>\)>
Function to be evaluated in browser context
### param: ElementHandle.$$eval.arg
- `arg` <[EvaluationArgument]>
Optional argument to pass to [`param: pageFunction`]
## async method: ElementHandle.boundingBox
- returns: <[null]|[Object]>
- `x` <[float]> the x coordinate of the element in pixels.
- `y` <[float]> the y coordinate of the element in pixels.
- `width` <[float]> the width of the element in pixels.
- `height` <[float]> the height of the element in pixels.
This method returns the bounding box of the element, or `null` 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 bonding box, similarly to
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/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](https://developer.mozilla.org/en-US/docs/Web/API/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.
```js
const box = await elementHandle.boundingBox();
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
```
## async method: ElementHandle.check
This method checks the element by performing the following steps:
1. Ensure that element is a checkbox or a radio input. If not, this method rejects. If the element is already checked, this method returns immediately.
1. Wait for [actionability](./actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element.
1. Wait for initiated navigations to either succeed or fail, unless [`option: noWaitAfter`] option is set.
1. Ensure that the element is now checked. If not, this method rejects.
If the element is detached from the DOM at any moment during the action, this method rejects.
When all steps combined have not finished during the specified [`option: timeout`], this method rejects with a
[TimeoutError]. Passing zero timeout disables this.
### option: ElementHandle.check.force = %%-input-force-%%
### option: ElementHandle.check.noWaitAfter = %%-input-no-wait-after-%%
### option: ElementHandle.check.timeout = %%-input-timeout-%%
## async method: ElementHandle.click
This method clicks the element by performing the following steps:
1. Wait for [actionability](./actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element, or the specified [`option: position`].
1. Wait for initiated navigations to either succeed or fail, unless [`option: noWaitAfter`] option is set.
If the element is detached from the DOM at any moment during the action, this method rejects.
When all steps combined have not finished during the specified [`option: timeout`], this method rejects with a
[TimeoutError]. Passing zero timeout disables this.
### option: ElementHandle.click.button = %%-input-button-%%
### option: ElementHandle.click.clickCount = %%-input-click-count-%%
### option: ElementHandle.click.delay = %%-input-down-up-delay-%%
### option: ElementHandle.click.position = %%-input-position-%%
### option: ElementHandle.click.modifiers = %%-input-modifiers-%%
### option: ElementHandle.click.force = %%-input-force-%%
### option: ElementHandle.click.noWaitAfter = %%-input-no-wait-after-%%
### option: ElementHandle.click.timeout = %%-input-timeout-%%
## async method: ElementHandle.contentFrame
- returns: <[null]|[Frame]>
Returns the content frame for element handles referencing iframe nodes, or `null` otherwise
## async method: ElementHandle.dblclick
This method double clicks the element by performing the following steps:
1. Wait for [actionability](./actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified [`option: position`].
1. Wait for initiated navigations to either succeed or fail, unless [`option: noWaitAfter`] option is set. Note that if the first click of the `dblclick()` triggers a navigation event, this method will reject.
If the element is detached from the DOM at any moment during the action, this method rejects.
When all steps combined have not finished during the specified [`option: timeout`], this method rejects with a
[TimeoutError]. Passing zero timeout disables this.
> **NOTE** `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event.
### option: ElementHandle.dblclick.button = %%-input-button-%%
### option: ElementHandle.dblclick.delay = %%-input-down-up-delay-%%
### option: ElementHandle.dblclick.position = %%-input-position-%%
### option: ElementHandle.dblclick.modifiers = %%-input-modifiers-%%
### option: ElementHandle.dblclick.force = %%-input-force-%%
### option: ElementHandle.dblclick.noWaitAfter = %%-input-no-wait-after-%%
### option: ElementHandle.dblclick.timeout = %%-input-timeout-%%
## async method: ElementHandle.dispatchEvent
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
is dispatched. This is equivalend to calling
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
```js
await elementHandle.dispatchEvent('click');
```
Under the hood, it creates an instance of an event based on the given [`param: type`], initializes it with [`param:
eventInit`] properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
Since [`param: eventInit`] is event-specific, please refer to the events documentation for the lists of initial
properties:
* [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
* [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
* [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
* [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
* [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
* [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
* [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
```js
// Note you can only create DataTransfer in Chromium and Firefox
const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
await elementHandle.dispatchEvent('dragstart', { dataTransfer });
```
### param: ElementHandle.dispatchEvent.type
- `type` <[string]>
DOM event type: `"click"`, `"dragstart"`, etc.
### param: ElementHandle.dispatchEvent.eventInit
- `eventInit` <[EvaluationArgument]>
Optional event-specific initialization properties.
## async method: ElementHandle.fill
This method waits for [actionability](./actionability.md) checks, focuses the element, fills it and triggers an `input`
event after filling. If the element is not an ``, `