Skip to main content
Module

x/astral/mod.ts>ElementHandle

A high-level puppeteer/playwright-like library for Deno
Latest
class ElementHandle
Re-export
import { ElementHandle } from "https://deno.land/x/astral@0.3.5/mod.ts";

ElementHandle represents an in-page DOM element.

Constructors

new
ElementHandle(
id: number,
celestial: Celestial,
page: Page,
)

Methods

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

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

$$(selector: string): Promise<ElementHandle[]>

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

boundingBox(): Promise<BoundingBox | null>

This method returns boxes of the element, 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(opts?: { offset?: Offset; })

This method scrolls element into view if needed, and then uses Page.mouse to click in the center of the element.

evaluate<E extends unknown, R extends AnyArray, T = unknown>(func: ElementEvaluateFunction<E, R, T> | string, evaluateOptions?: ElementEvaluateOptions<R>): Promise<T>

Executes the given function or string whose first argument is a DOM element and returns the result of the execution.

Calls focus on the element.

getAttribute(name: string): Promise<string | "" | null>

Returns the element.getAttribute

getAttributes(): Promise<Record<string, string>>

Retrieve the attributes of an element. Returns the key-value object

innerHTML(): Promise<string>

Returns the element.innerHTML

innerText(): Promise<string>

Returns the element.innerText

screenshot(opts?: Omit<ScreenshotOptions, "clip">): Promise<Uint8Array>

This method scrolls element into view if needed, and then uses Page.screenshot() to take a screenshot of the element.

Scrolls the element into view using the automation protocol client.

type(text: string, opts?: KeyboardTypeOptions)

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

waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>

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