Playwright Element Handle

View as Markdown

All Element Handle methods available when using the Playwright driver.

Access via elementHandle after launching a Playwright runtime.

Every method below is a remote call. The SDK translates it into a structured step sent to a single endpoint:

POST /v1/workspaces/{workspaceId}/execute
1{
2 "runtime": "my-browser",
3 "steps": [
4 {
5 "call": "element.goto",
6 "args": ["https://example.com"]
7 }
8 ]
9}

The call field maps directly to the method name. args is a JSON array of the method’s arguments. You can batch multiple steps in one request.

Actions

click(options?)

Click the element.

This method clicks the element by performing actionability checks, scrolling into view, and simulating a mouse click. Discouraged in favor of locator.click().

1await elementHandle.click();
ParameterTypeRequiredDescription
optionsPlaywrightClickOptionsNo

Upstream docs


dblclick(options?)

Double-click the element.

Discouraged in favor of locator.dblclick().

1await elementHandle.dblclick();
ParameterTypeRequiredDescription
optionsPlaywrightClickOptionsNo

Upstream docs


fill(value, options?)

Fill an input, textarea, or contenteditable element with the specified value.

This method waits for actionability checks, focuses the element, fills it, and triggers an input event. Pass empty string to clear. Discouraged in favor of locator.fill().

1await elementHandle.fill('...');
ParameterTypeRequiredDescription
valuestringYes
optionsPlaywrightFillOptionsNo

Upstream docs


type(text, options?)

Focus the element and type text into it character by character.

Deprecated: In most cases use locator.fill() instead. Only use this for special keyboard handling. For special keys use press().

1await elementHandle.type('...');
ParameterTypeRequiredDescription
textstringYes
optionsPlaywrightTypeOptionsNo

Upstream docs


press(key, options?)

Focus the element and press a key or key combination.

Key can be a single character or a special key like “Enter”, “Control+a”, “Shift+ArrowDown”. Discouraged in favor of locator.press().

1await elementHandle.press('...');
ParameterTypeRequiredDescription
keystringYes
optionsPlaywrightPressOptionsNo

Upstream docs


hover(options?)

Hover over the element.

This method hovers over the element by performing actionability checks, scrolling into view, and simulating mouse hover. Discouraged in favor of locator.hover().

1await elementHandle.hover();
ParameterTypeRequiredDescription
optionsPlaywrightHoverOptionsNo

Upstream docs


focus()

Focus the element.

Discouraged in favor of locator.focus().

1await elementHandle.focus();

Upstream docs


tap(options?)

Tap the element (for touch devices).

This method taps the element by performing actionability checks, scrolling into view, centering, and dispatching touchstart/touchend events. Discouraged in favor of locator.tap().

1await elementHandle.tap();
ParameterTypeRequiredDescription
optionsPlaywrightTapOptionsNo

Upstream docs


check(options?)

Check a checkbox or radio element.

If the element is already checked, this method returns immediately. Discouraged in favor of locator.check().

1await elementHandle.check();
ParameterTypeRequiredDescription
optionsPlaywrightCheckOptionsNo

Upstream docs


uncheck(options?)

Uncheck a checkbox element.

If the element is already unchecked, this method returns immediately. Discouraged in favor of locator.uncheck().

1await elementHandle.uncheck();
ParameterTypeRequiredDescription
optionsPlaywrightCheckOptionsNo

Upstream docs


setChecked(checked, options?)

Check or uncheck a checkbox or radio element.

Discouraged in favor of locator.setChecked().

1await elementHandle.setChecked(true);
ParameterTypeRequiredDescription
checkedbooleanYes
optionsPlaywrightCheckOptionsNo

Upstream docs


selectOption(values, options?)

Select one or more options in a <select> element.

Discouraged in favor of locator.selectOption().

1await elementHandle.selectOption(/* values */);
ParameterTypeRequiredDescription
valuesstring | string[] | PlaywrightSelectOption | PlaywrightSelectOption[]YesOptions to select. Can be value, label, or option object.
optionsPlaywrightSelectOptionOptionsNo

Returns string[] — An array of selected option values.

Upstream docs


setInputFiles(files, options?)

Set the files for a file input element.

Sets the value of the file input to these file paths or files. If some paths are relative, they are resolved relative to the current working directory. Clears selected files if empty array is passed. Discouraged in favor of locator.setInputFiles().

1await elementHandle.setInputFiles(/* files */);
ParameterTypeRequiredDescription
filesstring | string[] | PlaywrightFilePayload | PlaywrightFilePayload[]YesFile paths or file payloads to upload.
optionsPlaywrightSetInputFilesOptionsNo

Upstream docs


scrollIntoViewIfNeeded(options?)

Scroll the element into view if not already visible.

If the element is detached from DOM, throws an error. Discouraged in favor of locator.scrollIntoViewIfNeeded().

1await elementHandle.scrollIntoViewIfNeeded();
ParameterTypeRequiredDescription
optionsPlaywrightTimeoutOptionsNo

Upstream docs


dispatchEvent(type, eventInit?)

Dispatch a DOM event on the element.

The event is composed, cancelable and bubbles by default. Regardless of visibility, this will dispatch the event. Discouraged in favor of locator.dispatchEvent().

1await elementHandle.dispatchEvent('...');
ParameterTypeRequiredDescription
typestringYesDOM event type, e.g., “click”.
eventInitPlaywrightEventInitNoEvent-specific initialization properties.

Upstream docs


Queries

contentFrame()

Get the content frame for iframe elements.

1await elementHandle.contentFrame();

Returns RemotePlaywrightFrame \| null — The frame content, or null if not an iframe.

Upstream docs


$(selector)

Query for a child element matching the selector.

Discouraged in favor of locator-based locator.locator().

1await elementHandle.$('...');
ParameterTypeRequiredDescription
selectorstringYes

Returns RemotePlaywrightElementHandle \| null — The matching element or null if not found.

Upstream docs


$$(selector)

Query for all child elements matching the selector.

Discouraged in favor of locator-based locator.locator().

1await elementHandle.$$('...');
ParameterTypeRequiredDescription
selectorstringYes

Returns RemotePlaywrightElementHandle[] — An array of matching elements.

Upstream docs


Content

innerHTML()

Get the innerHTML of the element.

Discouraged in favor of locator.innerHTML().

1await elementHandle.innerHTML();

Returns string

Upstream docs


innerText()

Get the innerText of the element.

Discouraged in favor of locator.innerText().

1await elementHandle.innerText();

Returns string

Upstream docs


textContent()

Get the textContent of the element.

Discouraged in favor of locator.textContent().

1await elementHandle.textContent();

Returns string \| null

Upstream docs


getAttribute(name)

Get an attribute value of the element.

Discouraged in favor of locator.getAttribute().

1await elementHandle.getAttribute('...');
ParameterTypeRequiredDescription
namestringYesAttribute name to get.

Returns string \| null

Upstream docs


inputValue(options?)

Get the input value for input, textarea, or select elements.

Throws for non-input elements. Discouraged in favor of locator.inputValue().

1await elementHandle.inputValue();
ParameterTypeRequiredDescription
optionsPlaywrightTimeoutOptionsNo

Returns string

Upstream docs


boundingBox()

Get the bounding box of the element.

Discouraged in favor of locator.boundingBox().

1await elementHandle.boundingBox();

Returns PlaywrightBoundingBox \| null — Bounding box with x, y, width, height, or null if element is not visible.

Upstream docs


getProperty(propertyName)

Get a JSHandle for a property of this element.

Note: Returns serialized handle reference. Full JSHandle support not yet available.

1await elementHandle.getProperty('...');
ParameterTypeRequiredDescription
propertyNamestringYes

Returns unknown

Upstream docs


jsonValue()

Get the JSON value of the element.

Throws if the object cannot be serialized to JSON (e.g., DOM nodes).

1await elementHandle.jsonValue();

Returns T

Upstream docs


State Checks

isVisible()

Check if the element is visible.

Returns true if element is visible. Non-attached elements return false. Discouraged in favor of locator.isVisible().

1await elementHandle.isVisible();

Returns boolean

Upstream docs


isHidden()

Check if the element is hidden.

Returns true if element is hidden. Non-attached elements return true. Discouraged in favor of locator.isHidden().

1await elementHandle.isHidden();

Returns boolean

Upstream docs


isEnabled()

Check if the element is enabled.

Discouraged in favor of locator.isEnabled().

1await elementHandle.isEnabled();

Returns boolean

Upstream docs


isDisabled()

Check if the element is disabled.

Discouraged in favor of locator.isDisabled().

1await elementHandle.isDisabled();

Returns boolean

Upstream docs


isChecked()

Check if a checkbox or radio is checked.

Throws if element is not a checkbox or radio. Discouraged in favor of locator.isChecked().

1await elementHandle.isChecked();

Returns boolean

Upstream docs


isEditable()

Check if the element is editable.

Discouraged in favor of locator.isEditable().

1await elementHandle.isEditable();

Returns boolean

Upstream docs


Waiting

waitForElementState(state, options?)

Wait for the element to reach a specific state.

Discouraged in favor of web-first assertions.

1await elementHandle.waitForElementState(/* PlaywrightElementState */);
ParameterTypeRequiredDescription
statePlaywrightElementStateYesState to wait for: “visible”, “hidden”, “stable”, “enabled”, or “disabled”.
optionsPlaywrightTimeoutOptionsNo

Upstream docs


waitForSelector(selector, options?)

Wait for a child element matching the selector.

Discouraged in favor of locator-based assertions.

1await elementHandle.waitForSelector('...');
ParameterTypeRequiredDescription
selectorstringYes
optionsPlaywrightWaitForSelectorOptionsNo

Returns RemotePlaywrightElementHandle \| null — The matching element, or null if waiting for hidden/detached.

Upstream docs


Screenshots & PDF

screenshot(options?)

Take a screenshot of the element.

Returns base64-encoded image data. SDK converts to Buffer. Discouraged in favor of locator.screenshot().

1await elementHandle.screenshot();
ParameterTypeRequiredDescription
optionsPlaywrightScreenshotOptionsNo

Returns Buffer

Upstream docs


Evaluation

evaluate(pageFunction, arg?)

Evaluate a function in the context of the element.

The element is passed as the first argument to the function. If the function returns a Promise, it will be awaited.

1await elementHandle.evaluate('...');
ParameterTypeRequiredDescription
pageFunctionstring | ((element: Element, arg: Arg) =&gt; R | Promise&lt;R&gt;)YesFunction or string to evaluate in the page context.
argunknownNoArgument to pass to the function.

Returns R

Upstream docs


evaluateHandle(pageFunction, arg?)

Evaluate a function and return a JSHandle to the result.

The element is passed as the first argument. Note: Returns serialized handle reference. Full JSHandle support not yet available.

1await elementHandle.evaluateHandle('...');
ParameterTypeRequiredDescription
pageFunctionstring | ((element: Element, arg: Arg) =&gt; R | Promise&lt;R&gt;)YesFunction or string to evaluate in the page context.
argunknownNoArgument to pass to the function.

Returns unknown

Upstream docs


$eval(selector, pageFunction, arg?)

Evaluate a function on a child element matching the selector.

Throws if no element matches. Discouraged in favor of locator.evaluate().

1await elementHandle.$eval('...', '...');
ParameterTypeRequiredDescription
selectorstringYes
pageFunctionstring | ((element: Element, arg: Arg) =&gt; R | Promise&lt;R&gt;)Yes
argunknownNo

Returns R

Upstream docs


$$eval(selector, pageFunction, arg?)

Evaluate a function on all child elements matching the selector.

Discouraged in favor of locator.evaluateAll().

1await elementHandle.$$eval('...', '...');
ParameterTypeRequiredDescription
selectorstringYes
pageFunctionstring | ((elements: Element[], arg: Arg) =&gt; R | Promise&lt;R&gt;)Yes
argunknownNo

Returns R

Upstream docs


Other

ownerFrame()

Get the frame that owns this element.

1await elementHandle.ownerFrame();

Returns RemotePlaywrightFrame \| null — The owner frame, or null if element is detached.

Upstream docs


asElement()

Return this handle as an ElementHandle.

Since this is already an ElementHandle, returns itself.

1elementHandle.asElement();

Returns RemotePlaywrightElementHandle \| null

Upstream docs


dispose()

Dispose of the handle, releasing it from the browser.

After disposal, any method calls will throw. The SDK sets the disposed flag before the RPC call to prevent race conditions.

1await elementHandle.dispose();

Upstream docs


getProperties()

Get a map of property names to JSHandles.

1await elementHandle.getProperties();

Returns Map&lt;string, RemotePlaywrightJSHandle&gt;

Upstream docs