Inheritance
Extends:JSHandle<Node>
Constructor
ElementHandles are typically created through page methods likepage.$() or frame.$().
Frame Methods
ownerFrame
Returns the frame containing this element.Promise<Frame | null> - Owner frame or null
contentFrame
Returns the content frame for iframe elements.Promise<Frame | null> - Content frame or null
Action Methods
click
Clicks the element.Click options
button(‘left’ | ‘right’ | ‘middle’): Mouse buttonclickCount(number): Number of clicksdelay(number): Delay between mousedown and mouseupposition(object): Click positionmodifiers(string[]): Modifier keysforce(boolean): Force clicknoWaitAfter(boolean): Don’t wait after clicktimeout(number): Maximum time
Promise<void>
dblclick
Double clicks the element.tap
Taps the element.hover
Hovers over the element.Hover options
position(object): Hover positionmodifiers(string[]): Modifier keysforce(boolean): Force hovertimeout(number): Maximum time
Promise<void>
fill
Fills an input element.Value to fill
Fill options
force(boolean): Force fillnoWaitAfter(boolean): Don’t wait after filltimeout(number): Maximum time
Promise<void>
type
Types text into the element.Text to type
Type options
delay(number): Delay between key presses in millisecondsnoWaitAfter(boolean): Don’t wait after typingtimeout(number): Maximum time
Promise<void>
press
Presses a key.Key to press (e.g., ‘Enter’, ‘ArrowDown’, ‘Control+A’)
Press options
delay(number): Delay between keydown and keyupnoWaitAfter(boolean): Don’t wait after presstimeout(number): Maximum time
Promise<void>
check
Checks a checkbox or radio button.Check options
force(boolean): Force checknoWaitAfter(boolean): Don’t wait after checktimeout(number): Maximum time
Promise<void>
uncheck
Unchecks a checkbox.setChecked
Sets checkbox state.Whether to check or uncheck
Check options
Promise<void>
selectOption
Selects options in a<select> element.
Values to select
Select options
force(boolean): Force selectnoWaitAfter(boolean): Don’t wait after selecttimeout(number): Maximum time
Promise<string[]> - Array of selected option values
focus
Focuses the element.Promise<void>
setInputFiles
Sets files for a file input element.File paths or file payloads to upload
Upload options
noWaitAfter(boolean): Don’t wait after setting filestimeout(number): Maximum time
Promise<void>
dispatchEvent
Dispatches a DOM event.Event type (e.g., ‘click’, ‘submit’)
Event initialization object
Promise<void>
Content Methods
textContent
Returns element’s text content.Promise<string | null> - Text content or null
innerText
Returns element’s inner text.Promise<string> - Inner text
innerHTML
Returns element’s inner HTML.Promise<string> - Inner HTML
getAttribute
Returns attribute value.Attribute name
Promise<string | null> - Attribute value or null
inputValue
Returns input value.Promise<string> - Input value
State Methods
isVisible
Checks if element is visible.Promise<boolean> - True if visible
isHidden
Checks if element is hidden.Promise<boolean> - True if hidden
isEnabled
Checks if element is enabled.Promise<boolean> - True if enabled
isDisabled
Checks if element is disabled.Promise<boolean> - True if disabled
isChecked
Checks if checkbox or radio is checked.Promise<boolean> - True if checked
isEditable
Checks if element is editable.Promise<boolean> - True if editable
Selector Methods
$
Finds a descendant element.Selector to query
Promise<ElementHandle | null> - Element handle or null
$$
Finds all descendant elements.Selector to query
Promise<ElementHandle[]> - Array of element handles
$eval
Evaluates function on a descendant element.Selector to query
Function to evaluate
Argument to pass to function
Promise<R> - Evaluation result
$$eval
Evaluates function on all descendant elements.waitForSelector
Waits for a descendant element.Selector to wait for
Wait options
state(‘attached’ | ‘visible’ | ‘hidden’ | ‘detached’): Element statetimeout(number): Maximum time
Promise<ElementHandle | null> - Element handle or null
Utility Methods
boundingBox
Returns element’s bounding box.Promise<Rect | null> - Bounding box or null
screenshot
Takes a screenshot of the element.Screenshot options
path(string): File path to save totype(‘png’ | ‘jpeg’): Image typequality(number): JPEG quality (0-100)omitBackground(boolean): Transparent backgroundtimeout(number): Maximum timemask(Locator[]): Elements to mask
Promise<Buffer> - Screenshot buffer
scrollIntoViewIfNeeded
Scrolls element into view if needed.Scroll options
timeout(number): Maximum time
Promise<void>
selectText
Selects text in the element.Timeout options
Promise<void>
waitForElementState
Waits for element to reach a specific state.State to wait for
visible: Element is visiblehidden: Element is hiddenstable: Element is stable (not animating)enabled: Element is enableddisabled: Element is disabled
Timeout options
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
-
Memory Management: Always dispose of ElementHandles when done to prevent memory leaks:
-
Prefer Locators: Locators are recommended over ElementHandles for most use cases:
- Stale References: ElementHandles can become stale if the DOM changes. Locators automatically re-query.
-
Auto-Waiting: Unlike Locators, ElementHandles don’t automatically wait for actionability. Use
waitForElementState()when needed.
