Playwright Locator

View as Markdown

All Locator methods available when using the Playwright driver.

Access via runtime.page.locator(...) 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": "locator.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?)

Clicks on the element.

Waits for actionability checks, scrolls element into view, and uses Page.mouse to click in the center of the element.

1await locator.click();
ParameterTypeRequiredDescription
optionsPlaywrightClickOptionsNo

Upstream docs


dblclick(options?)

Double-clicks on the element.

Performs two clicks with a short delay, simulating a native double-click. Waits for actionability checks before performing the action.

1await runtime.page.locator(...).dblclick();
ParameterTypeRequiredDescription
optionsPlaywrightDblclickOptionsNo

Upstream docs


fill(value, options?)

Fills an input or textarea element with the specified value.

This method waits for actionability checks, focuses the element, fills it, and triggers an input event. It clears the existing value before filling. Works with <input>, <textarea>, and [contenteditable] elements.

1await page.getByLabel('Password').fill('secret');
ParameterTypeRequiredDescription
valuestringYesValue to fill in
optionsPlaywrightFillOptionsNo

Upstream docs


clear(options?)

Clears the input field.

Waits for actionability checks, focuses the element, clears it, and triggers an input event.

1await runtime.page.locator(...).clear();
ParameterTypeRequiredDescription
optionsPlaywrightClearOptionsNo

Upstream docs


press(key, options?)

Presses a single key or key combination.

Focuses the element, then uses keyboard.down() and keyboard.up(). Supports modifier keys like Control, Shift, Alt, Meta.

1await locator.press('Enter');
ParameterTypeRequiredDescription
keystringYesKey to press (e.g., “Enter”, “Control+A”)
optionsPlaywrightPressOptionsNo

Upstream docs


pressSequentially(text, options?)

Types text character by character with keydown, keypress, and keyup events.

Use this for special keyboard handling. In most cases, fill() is preferred. The delay option can simulate realistic typing speed.

1await locator.pressSequentially('Hello');
ParameterTypeRequiredDescription
textstringYesCharacters to type
optionsPlaywrightPressSequentiallyOptionsNo

Upstream docs


type(text, options?)

Types text into the element (DEPRECATED - use fill() or pressSequentially()).

This method is deprecated. Use fill() for most cases, or pressSequentially() when special keyboard handling is required.

1await runtime.page.locator(...).type('...');
ParameterTypeRequiredDescription
textstringYes
options{ delay?: number; noWaitAfter?: boolean; timeout?: number }No

Upstream docs


hover(options?)

Hovers over the element.

Waits for actionability checks, scrolls element into view, and moves mouse to the center of the element.

1await runtime.page.locator(...).hover();
ParameterTypeRequiredDescription
optionsPlaywrightHoverOptionsNo

Upstream docs


tap(options?)

Performs a tap gesture on the element.

Requires hasTouch option to be enabled in browser context. Waits for actionability checks before performing the tap.

1await runtime.page.locator(...).tap();
ParameterTypeRequiredDescription
optionsPlaywrightTapOptionsNo

Upstream docs


focus(options?)

Focuses the element.

1await runtime.page.locator(...).focus();
ParameterTypeRequiredDescription
optionsPlaywrightFocusOptionsNo

Upstream docs


blur(options?)

Removes focus from the element.

1await runtime.page.locator(...).blur();
ParameterTypeRequiredDescription
optionsPlaywrightBlurOptionsNo

Upstream docs


check(options?)

Checks a checkbox or radio button.

If already checked, this method does nothing.

1await runtime.page.locator(...).check();
ParameterTypeRequiredDescription
optionsPlaywrightCheckOptionsNo

Upstream docs


uncheck(options?)

Unchecks a checkbox.

If already unchecked, this method does nothing.

1await runtime.page.locator(...).uncheck();
ParameterTypeRequiredDescription
optionsPlaywrightUncheckOptionsNo

Upstream docs


setChecked(checked, options?)

Sets the checked state of a checkbox or radio button.

1await runtime.page.locator(...).setChecked(true);
ParameterTypeRequiredDescription
checkedbooleanYesWhether to check or uncheck
optionsPlaywrightSetCheckedOptionsNo

Upstream docs


selectOption(values, options?)

Selects option(s) in a <select> element.

Waits for actionability checks, waits until all options are present, and triggers change and input events. Returns array of selected option values.

1await locator.selectOption('blue');
ParameterTypeRequiredDescription
valuesstring | string[] | PlaywrightSelectOptionValue | PlaywrightSelectOptionValue[]YesOptions to select by value, label, or index
optionsPlaywrightSelectOptionOptionsNo

Returns string[]

Upstream docs


selectText(options?)

Selects all text content of the element.

This method waits for actionability checks, then focuses the element and selects all text content.

1await runtime.page.locator(...).selectText();
ParameterTypeRequiredDescription
options{ force?: boolean; timeout?: number }No

Upstream docs


setInputFiles(files, options?)

Sets files for a file input element.

Pass empty array to clear selected files. Supports paths, objects with name/mimeType/buffer, or directories.

1await locator.setInputFiles('file.pdf');
ParameterTypeRequiredDescription
filesstring | string[] | PlaywrightFilePayload | PlaywrightFilePayload[]YesFile paths or file objects to upload
optionsPlaywrightSetInputFilesOptionsNo

Upstream docs


dragTo(target, options?)

Drags this element to the target element.

Performs mousedown on source, moves to target, and releases with mouseup. Supports sourcePosition and targetPosition options for precise control.

1await source.dragTo(target);
ParameterTypeRequiredDescription
targetRemotePlaywrightLocatorYesTarget locator to drag to
optionsPlaywrightDragToOptionsNo

Upstream docs


scrollIntoViewIfNeeded(options?)

Scrolls the element into view if not already visible.

Uses IntersectionObserver to determine if element is already visible.

1await runtime.page.locator(...).scrollIntoViewIfNeeded();
ParameterTypeRequiredDescription
optionsPlaywrightScrollIntoViewIfNeededOptionsNo

Upstream docs


dispatchEvent(type, eventInit?, options?)

Programmatically dispatches a DOM event on the element.

The event is created as composed, cancelable, and bubbles by default. Works regardless of element visibility state.

1await locator.dispatchEvent('click');
ParameterTypeRequiredDescription
typestringYesDOM event type (e.g., “click”, “dragstart”)
eventInitRecord&lt;string, unknown&gt;NoEvent initialization properties
optionsPlaywrightDispatchEventOptionsNo

Upstream docs


highlight()

Highlights the element on screen (for debugging).

Useful for debugging during test development. Not recommended for production tests.

1await runtime.page.locator(...).highlight();

Upstream docs


Queries

count()

Returns the number of elements matching this locator.

For assertions, prefer expect(locator).toHaveCount() to avoid flakiness.

1const count = await page.getByRole('listitem').count();

Returns number

Upstream docs


first()

Returns locator to the first matching element.

1runtime.page.locator(...).first();

Returns RemotePlaywrightLocator

Upstream docs


last()

Returns locator to the last matching element.

1runtime.page.locator(...).last();

Returns RemotePlaywrightLocator

Upstream docs


nth(index)

Returns locator to the nth matching element.

Index is zero-based. Negative indices count from the end (-1 is last).

1runtime.page.locator(...).nth(0);
ParameterTypeRequiredDescription
indexnumberYesZero-based index

Returns RemotePlaywrightLocator

Upstream docs


locator(selectorOrLocator, options?)

Creates a locator matching descendants of this element.

Accepts CSS, XPath, or text selectors. Can also accept another locator.

1const button = row.locator('button.submit');
ParameterTypeRequiredDescription
selectorOrLocatorstring | RemotePlaywrightLocatorYesSelector or locator to match descendants
optionsPlaywrightLocatorOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


filter(options?)

Narrows the locator with additional filters.

Supports has, hasNot, hasText, hasNotText, and visible options. Multiple filters can be chained.

1const row = page.locator('tr').filter({ hasText: 'John' });
ParameterTypeRequiredDescription
optionsPlaywrightLocatorFilterOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


and(locator)

Creates a locator that matches both this locator AND the argument.

Both conditions must be satisfied for an element to match.

1const button = page.getByRole('button').and(page.getByTitle('Subscribe'));
ParameterTypeRequiredDescription
locatorRemotePlaywrightLocatorYesAdditional locator to match

Returns RemotePlaywrightLocator

Upstream docs


or(locator)

Creates a locator that matches this locator OR the argument.

Either condition being satisfied will match. Be careful with strict mode - if both match, use .first() to select one.

1const btnOrLink = page.getByRole('button').or(page.getByRole('link'));
ParameterTypeRequiredDescription
locatorRemotePlaywrightLocatorYesAlternative locator to match

Returns RemotePlaywrightLocator

Upstream docs


all()

Returns array of locators pointing to all matching elements.

Does not wait for elements. Use with caution on dynamic lists. Wait for the list to stabilize before calling.

1for (const li of await page.getByRole('listitem').all()) {
2 await li.click();
3}

Returns RemotePlaywrightLocator[]

Upstream docs


getByRole(role, options?)

Locates elements by their ARIA role.

Matches by implicit ARIA role (e.g., <button>) or explicit role attribute. Options include name, checked, disabled, expanded, etc.

1await locator.getByRole('button', { name: 'Submit' }).click();
ParameterTypeRequiredDescription
rolePlaywrightAriaRoleYesARIA role to match
optionsPlaywrightGetByRoleOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByText(text, options?)

Locates elements containing the specified text.

Matches case-insensitively by default. Use exact: true for exact match.

1await locator.getByText('Welcome').click();
ParameterTypeRequiredDescription
textstring | RegExpYesText or pattern to match
optionsPlaywrightGetByTextOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByLabel(text, options?)

Locates form elements by their associated label text.

Matches <label> text, aria-label, or aria-labelledby.

1await locator.getByLabel('Email').fill('[email protected]');
ParameterTypeRequiredDescription
textstring | RegExpYesLabel text or pattern
optionsPlaywrightGetByLabelOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByPlaceholder(text, options?)

Locates input elements by their placeholder text.

1await locator.getByPlaceholder('Search...').fill('query');
ParameterTypeRequiredDescription
textstring | RegExpYesPlaceholder text or pattern
optionsPlaywrightGetByPlaceholderOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByAltText(text, options?)

Locates elements by their alt attribute (typically images).

1await locator.getByAltText('Company Logo').click();
ParameterTypeRequiredDescription
textstring | RegExpYesAlt text or pattern
optionsPlaywrightGetByAltTextOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByTitle(text, options?)

Locates elements by their title attribute.

1await locator.getByTitle('More information').click();
ParameterTypeRequiredDescription
textstring | RegExpYesTitle attribute text or pattern
optionsPlaywrightGetByTitleOptionsNo

Returns RemotePlaywrightLocator

Upstream docs


getByTestId(testId)

Locates elements by their test ID attribute.

Default attribute is data-testid. Can be configured via selectors.setTestIdAttribute().

1await locator.getByTestId('submit-button').click();
ParameterTypeRequiredDescription
testIdstring | RegExpYesTest ID value or pattern

Returns RemotePlaywrightLocator

Upstream docs


contentFrame()

Returns a FrameLocator pointing to the iframe this locator points to.

Useful when you have a Locator to an iframe and want to interact with its content.

1const frameLocator = locator.contentFrame();
2await frameLocator.getByRole('button').click();

Returns RemotePlaywrightFrameLocator

Upstream docs


frameLocator(selector)

Returns a FrameLocator for an iframe within this element.

Use to interact with content inside iframes.

1const frame = locator.frameLocator('iframe.content');
ParameterTypeRequiredDescription
selectorstringYesCSS selector for iframe

Returns RemotePlaywrightFrameLocator

Upstream docs


page()

Returns the Page that this locator belongs to.

1runtime.page.locator(...).page();

Returns RemotePlaywrightPage

Upstream docs


Content

innerHTML(options?)

Returns the innerHTML of the element.

1await runtime.page.locator(...).innerHTML();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns string

Upstream docs


innerText(options?)

Returns the innerText of the element.

For assertions, prefer expect(locator).toHaveText() with useInnerText option.

1await runtime.page.locator(...).innerText();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns string

Upstream docs


textContent(options?)

Returns the textContent of the element.

For assertions, prefer expect(locator).toHaveText().

1await runtime.page.locator(...).textContent();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns string \| null

Upstream docs


allInnerTexts()

Returns an array of innerText values for all matching elements.

For assertions, prefer expect(locator).toHaveText() with useInnerText option.

1const texts = await page.getByRole('link').allInnerTexts();

Returns string[]

Upstream docs


allTextContents()

Returns an array of textContent values for all matching elements.

For assertions, prefer expect(locator).toHaveText().

1const texts = await page.getByRole('link').allTextContents();

Returns string[]

Upstream docs


getAttribute(name, options?)

Returns the attribute value of the element.

1await runtime.page.locator(...).getAttribute('...');
ParameterTypeRequiredDescription
namestringYesAttribute name
options{ timeout?: number }No

Returns string \| null

Upstream docs


inputValue(options?)

Returns the input value for <input>, <textarea>, or <select> elements.

1await runtime.page.locator(...).inputValue();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns string

Upstream docs


boundingBox(options?)

Returns the bounding box of the element, or null if not visible.

Returns { x, y, width, height } in pixels relative to the main frame viewport. Scrolling affects the coordinates. Returns null if element is not visible.

1const box = await locator.boundingBox();
2await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
ParameterTypeRequiredDescription
optionsPlaywrightBoundingBoxOptionsNo

Returns PlaywrightBoundingBox \| null

Upstream docs


State Checks

isVisible(options?)

Returns whether the element is visible.

Does not wait for element to appear. For assertions, prefer expect(locator).toBeVisible().

1await runtime.page.locator(...).isVisible();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


isHidden(options?)

Returns whether the element is hidden.

Opposite of isVisible(). For assertions, prefer expect(locator).toBeHidden().

1await runtime.page.locator(...).isHidden();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


isEnabled(options?)

Returns whether the element is enabled.

For assertions, prefer expect(locator).toBeEnabled().

1await runtime.page.locator(...).isEnabled();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


isDisabled(options?)

Returns whether the element is disabled.

For assertions, prefer expect(locator).toBeDisabled().

1await runtime.page.locator(...).isDisabled();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


isChecked(options?)

Returns whether a checkbox or radio is checked.

For assertions, prefer expect(locator).toBeChecked().

1await runtime.page.locator(...).isChecked();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


isEditable(options?)

Returns whether the element is editable.

For assertions, prefer expect(locator).toBeEditable().

1await runtime.page.locator(...).isEditable();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns boolean

Upstream docs


Waiting

waitFor(options?)

Waits for element to satisfy the given state.

State options: ‘attached’, ‘detached’, ‘visible’, ‘hidden’. Returns immediately if condition is already met. Default state is ‘visible’.

1await locator.waitFor();
ParameterTypeRequiredDescription
optionsPlaywrightWaitForOptionsNo

Upstream docs


Screenshots & PDF

screenshot(options?)

Takes a screenshot of the element.

Waits for actionability checks and scrolls element into view. Returns screenshot clipped to element size and position.

1await runtime.page.locator(...).screenshot();
ParameterTypeRequiredDescription
optionsPlaywrightScreenshotOptionsNo

Returns Buffer

Upstream docs


Evaluation

evaluate(pageFunction, arg?, options?)

Evaluates a function in the browser context with the element as first argument.

Returns the value of the evaluated function. The function receives the DOM element as first argument.

1const tagName = await locator.evaluate(el => el.tagName);
ParameterTypeRequiredDescription
pageFunctionstring | ((element: Element, arg: Arg) =&gt; R | Promise&lt;R&gt;)YesFunction to evaluate in browser context
argArgNoArgument to pass to function
optionsPlaywrightEvaluateOptionsNo

Returns R

Upstream docs


evaluateAll(pageFunction, arg?)

Evaluates a function with all matching elements as first argument.

Does not wait for elements - returns empty array if none match.

1const count = await locator.evaluateAll(els => els.length);
ParameterTypeRequiredDescription
pageFunctionstring | ((elements: Element[], arg: Arg) =&gt; R | Promise&lt;R&gt;)YesFunction to evaluate in browser context
argArgNoArgument to pass to function

Returns R

Upstream docs


evaluateHandle(pageFunction, arg?)

Returns a JSHandle with the result of the evaluation.

Use when you need to retain a reference to a JavaScript object in the page. Note: JSHandle is not fully supported in the remote SDK.

1await runtime.page.locator(...).evaluateHandle(/* pageFunction */);
ParameterTypeRequiredDescription
pageFunctionstring | ((element: Element, arg: Arg) =&gt; R | Promise&lt;R&gt;)YesFunction to evaluate in browser context
argArgNoArgument to pass to function

Returns unknown

Upstream docs


Other

elementHandle(options?)

Resolves to the ElementHandle of the element.

Returns the handle to the element that matches this locator. Throws if no elements or multiple elements match.

1await runtime.page.locator(...).elementHandle();
ParameterTypeRequiredDescription
options{ timeout?: number }No

Returns RemotePlaywrightElementHandle

Upstream docs


elementHandles()

Resolves to all ElementHandles matching this locator.

Returns an empty array if no elements match.

1await runtime.page.locator(...).elementHandles();

Returns RemotePlaywrightElementHandle[]

Upstream docs