Skip to main content
Module

x/puppeteer/mod.ts>ElementHandle

A port of puppeteer running on Deno
Latest
class ElementHandle
extends JSHandle<ElementType>
Re-export
import { ElementHandle } from "https://deno.land/x/puppeteer@16.2.0/mod.ts";

ElementHandle represents an in-page DOM element.

Constructors

new
ElementHandle(
context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject,
frame: Frame,
page: Page,
frameManager: FrameManager,
)

Type Parameters

optional
ElementType extends any = any

Methods

$<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>

Queries the current element for an element matching the given selector.

$$<Selector extends string>(selector: Selector): Promise<Array<ElementHandle<NodeFor<Selector>>>>

Queries the current element for all elements matching the given selector.

$$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFunc<[Array<NodeFor<Selector>>, ...Params]> = EvaluateFunc<[Array<NodeFor<Selector>>, ...Params]>>(
selector: Selector,
pageFunction: Func | string,
...args: Params,
): Promise<Awaited<ReturnType<Func>>>

Runs the given function on an array of elements matching the given selector in the current element.

If the given function returns a promise, then this method will wait till the promise resolves.

$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFunc<[ElementHandle<NodeFor<Selector>>, ...Params]> = EvaluateFunc<[ElementHandle<NodeFor<Selector>>, ...Params]>>(
selector: Selector,
pageFunction: Func | string,
...args: Params,
): Promise<Awaited<ReturnType<Func>>>

Runs the given function on the first element matching the given selector in the current element.

If the given function returns a promise, then this method will wait till the promise resolves.

deprecated
$x(expression: string): Promise<Array<ElementHandle<any>>>
asElement(): ElementHandle<ElementType> | null
boundingBox(): Promise<BoundingBox | null>

This method returns the bounding box of the element (relative to the main frame), or null if the element is not visible.

boxModel(): Promise<BoxModel | null>

This method returns boxes of the element, or null if the element is not visible.

click(this: ElementHandle<any>, options?: ClickOptions): Promise<void>

This method scrolls element into view if needed, and then uses Page.mouse to click in the center of the element. If the element is detached from DOM, the method throws an error.

clickablePoint(offset?: Offset): Promise<Point>

Returns the middle point within an element unless a specific offset is provided.

contentFrame(): Promise<Frame | null>

Resolves to the content frame for element handles referencing iframe nodes, or null otherwise

drag(this: ElementHandle<any>, target: Point): Promise<Protocol.Input.DragData>

This method creates and captures a dragevent from the element.

dragAndDrop(
this: ElementHandle<any>,
target: ElementHandle<any>,
options?: { delay: number; },
): Promise<void>

This method triggers a dragenter, dragover, and drop on the element.

dragEnter(this: ElementHandle<any>, data?: Protocol.Input.DragData): Promise<void>

This method creates a dragenter event on the element.

dragOver(this: ElementHandle<any>, data?: Protocol.Input.DragData): Promise<void>

This method creates a dragover event on the element.

drop(this: ElementHandle<any>, data?: Protocol.Input.DragData): Promise<void>

This method triggers a drop on the element.

focus(): Promise<void>

Calls focus on the element.

hover(this: ElementHandle<any>): Promise<void>

This method scrolls element into view if needed, and then uses Page.mouse to hover over the center of the element. If the element is detached from DOM, the method throws an error.

isIntersectingViewport(this: ElementHandle<any>, options?: { threshold?: number; }): Promise<boolean>

Resolves to true if the element is visible in the current viewport.

press(key: KeyInput, options?: PressOptions): Promise<void>

Focuses the element, and then uses Keyboard.down and Keyboard.up.

screenshot(this: ElementHandle<any>, options?: ScreenshotOptions): Promise<string | Buffer>

This method scrolls element into view if needed, and then uses Page.screenshot to take a screenshot of the element. If the element is detached from DOM, the method throws an error.

select(...values: string[]): Promise<string[]>

Triggers a change and input event once all the provided options have been selected. If there's no <select> element matching selector, the method throws an error.

tap(this: ElementHandle<any>): Promise<void>

This method scrolls element into view if needed, and then uses Touchscreen.tap to tap in the center of the element. If the element is detached from DOM, the method throws an error.

type(text: string, options?: { delay: number; }): Promise<void>

Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.

To press a special key, like Control or ArrowDown, use ElementHandle.press.

uploadFile(this: ElementHandle<any>, ...filePaths: string[]): Promise<void>

This method expects elementHandle to point to an input element.

waitForSelector<Selector extends string>(selector: Selector, options?: Exclude<WaitForSelectorOptions, "root">): Promise<ElementHandle<NodeFor<Selector>> | null>

Wait for an element matching the given selector to appear in the current element.

Unlike Frame.waitForSelector, this method does not work across navigations or if the element is detached from DOM.

deprecated
waitForXPath(xpath: string, options?: { visible?: boolean; hidden?: boolean; timeout?: number; }): Promise<ElementHandle<any> | null>