Skip to main content
ElementHandle represents an in-page DOM element. ElementHandles are discouraged in favor of Locators, but they are useful when you need to retain a reference to a specific element.

Inheritance

Extends: JSHandle<Node>

Constructor

ElementHandles are typically created through page methods like page.$() or frame.$().

Frame Methods

ownerFrame

Returns the frame containing this element.
Returns: Promise<Frame | null> - Owner frame or null

contentFrame

Returns the content frame for iframe elements.
Returns: Promise<Frame | null> - Content frame or null

Action Methods

click

Clicks the element.
ClickOptions
Click options
  • button (‘left’ | ‘right’ | ‘middle’): Mouse button
  • clickCount (number): Number of clicks
  • delay (number): Delay between mousedown and mouseup
  • position (object): Click position
  • modifiers (string[]): Modifier keys
  • force (boolean): Force click
  • noWaitAfter (boolean): Don’t wait after click
  • timeout (number): Maximum time
Returns: Promise<void>

dblclick

Double clicks the element.

tap

Taps the element.

hover

Hovers over the element.
HoverOptions
Hover options
  • position (object): Hover position
  • modifiers (string[]): Modifier keys
  • force (boolean): Force hover
  • timeout (number): Maximum time
Returns: Promise<void>

fill

Fills an input element.
string
required
Value to fill
FillOptions
Fill options
  • force (boolean): Force fill
  • noWaitAfter (boolean): Don’t wait after fill
  • timeout (number): Maximum time
Returns: Promise<void>

type

Types text into the element.
string
required
Text to type
TypeOptions
Type options
  • delay (number): Delay between key presses in milliseconds
  • noWaitAfter (boolean): Don’t wait after typing
  • timeout (number): Maximum time
Returns: Promise<void>

press

Presses a key.
string
required
Key to press (e.g., ‘Enter’, ‘ArrowDown’, ‘Control+A’)
PressOptions
Press options
  • delay (number): Delay between keydown and keyup
  • noWaitAfter (boolean): Don’t wait after press
  • timeout (number): Maximum time
Returns: Promise<void>

check

Checks a checkbox or radio button.
CheckOptions
Check options
  • force (boolean): Force check
  • noWaitAfter (boolean): Don’t wait after check
  • timeout (number): Maximum time
Returns: Promise<void>

uncheck

Unchecks a checkbox.

setChecked

Sets checkbox state.
boolean
required
Whether to check or uncheck
CheckOptions
Check options
Returns: Promise<void>

selectOption

Selects options in a <select> element.
string | string[] | ElementHandle | ElementHandle[] | SelectOption | SelectOption[]
required
Values to select
SelectOptionOptions
Select options
  • force (boolean): Force select
  • noWaitAfter (boolean): Don’t wait after select
  • timeout (number): Maximum time
Returns: Promise<string[]> - Array of selected option values

focus

Focuses the element.
Returns: Promise<void>

setInputFiles

Sets files for a file input element.
string | string[] | FilePayload | FilePayload[]
required
File paths or file payloads to upload
SetInputFilesOptions
Upload options
  • noWaitAfter (boolean): Don’t wait after setting files
  • timeout (number): Maximum time
Returns: Promise<void>

dispatchEvent

Dispatches a DOM event.
string
required
Event type (e.g., ‘click’, ‘submit’)
any
Event initialization object
Returns: Promise<void>

Content Methods

textContent

Returns element’s text content.
Returns: Promise<string | null> - Text content or null

innerText

Returns element’s inner text.
Returns: Promise<string> - Inner text

innerHTML

Returns element’s inner HTML.
Returns: Promise<string> - Inner HTML

getAttribute

Returns attribute value.
string
required
Attribute name
Returns: Promise<string | null> - Attribute value or null

inputValue

Returns input value.
Returns: Promise<string> - Input value

State Methods

isVisible

Checks if element is visible.
Returns: Promise<boolean> - True if visible

isHidden

Checks if element is hidden.
Returns: Promise<boolean> - True if hidden

isEnabled

Checks if element is enabled.
Returns: Promise<boolean> - True if enabled

isDisabled

Checks if element is disabled.
Returns: Promise<boolean> - True if disabled

isChecked

Checks if checkbox or radio is checked.
Returns: Promise<boolean> - True if checked

isEditable

Checks if element is editable.
Returns: Promise<boolean> - True if editable

Selector Methods

$

Finds a descendant element.
string
required
Selector to query
Returns: Promise<ElementHandle | null> - Element handle or null

$$

Finds all descendant elements.
string
required
Selector to query
Returns: Promise<ElementHandle[]> - Array of element handles

$eval

Evaluates function on a descendant element.
string
required
Selector to query
Function
required
Function to evaluate
any
Argument to pass to function
Returns: Promise<R> - Evaluation result

$$eval

Evaluates function on all descendant elements.

waitForSelector

Waits for a descendant element.
string
required
Selector to wait for
WaitForSelectorOptions
Wait options
  • state (‘attached’ | ‘visible’ | ‘hidden’ | ‘detached’): Element state
  • timeout (number): Maximum time
Returns: Promise<ElementHandle | null> - Element handle or null

Utility Methods

boundingBox

Returns element’s bounding box.
Returns: Promise<Rect | null> - Bounding box or null

screenshot

Takes a screenshot of the element.
ScreenshotOptions
Screenshot options
  • path (string): File path to save to
  • type (‘png’ | ‘jpeg’): Image type
  • quality (number): JPEG quality (0-100)
  • omitBackground (boolean): Transparent background
  • timeout (number): Maximum time
  • mask (Locator[]): Elements to mask
Returns: Promise<Buffer> - Screenshot buffer

scrollIntoViewIfNeeded

Scrolls element into view if needed.
ScrollOptions
Scroll options
  • timeout (number): Maximum time
Returns: Promise<void>

selectText

Selects text in the element.
TimeoutOptions
Timeout options
Returns: Promise<void>

waitForElementState

Waits for element to reach a specific state.
string
required
State to wait for
  • visible: Element is visible
  • hidden: Element is hidden
  • stable: Element is stable (not animating)
  • enabled: Element is enabled
  • disabled: Element is disabled
TimeoutOptions
Timeout options
Returns: Promise<void>

Usage Examples

Basic ElementHandle Usage

Querying Descendants

Getting Element Properties

Form Interactions

Taking Element Screenshots

Working with Frames

Waiting for Element State

Important Notes

  1. Memory Management: Always dispose of ElementHandles when done to prevent memory leaks:
  2. Prefer Locators: Locators are recommended over ElementHandles for most use cases:
  3. Stale References: ElementHandles can become stale if the DOM changes. Locators automatically re-query.
  4. Auto-Waiting: Unlike Locators, ElementHandles don’t automatically wait for actionability. Use waitForElementState() when needed.
  • Locator - Modern element selection (recommended)
  • Page - Page methods for querying elements
  • Frame - Frame methods for querying elements
  • JSHandle - Base class for JavaScript object handles