ElementHandle
ElementHandle represents a resolved element — a snapshot with a CSS selector and a reference to the page. Created via page.$(), page.$$(), or locator.toElement().
const handle = await page.$("css:button");const element = await page.locator("role:button").toElement();Unlike Locator, ElementHandle holds a resolved CSS selector and does not re-query on each action.
Methods
Section titled “Methods”| Method | Signature |
|---|---|
click |
click(): Promise<void> |
dblClick |
dblClick(): Promise<void> |
type |
type(text: string): Promise<void> |
press |
press(key: string, modifiers?: Bun.WebView.Modifier[]): Promise<void> |
screenshot |
screenshot(opts?: { path?: string; }): Promise<void> |
evaluate<T> |
evaluate<T>(fn: (el: Element) => T): Promise<T> |
innerText |
innerText(): Promise<string> |
innerHTML |
innerHTML(): Promise<string> |
getAttribute |
getAttribute(name: string): Promise<string | null> |
isVisible |
isVisible(): Promise<boolean> |
isEnabled |
isEnabled(): Promise<boolean> |
Actions
Section titled “Actions”await handle.click();await handle.dblClick();await handle.type("Hello");await handle.press("Enter");await handle.screenshot({ path: "./element.png" });Reading
Section titled “Reading”const text = await handle.innerText();const html = await handle.innerHTML();const value = await handle.getAttribute("href");const result = await handle.evaluate((el) => el.tagName);const visible = await handle.isVisible(); // booleanconst enabled = await handle.isEnabled(); // boolean