Playwright Locator
All Locator methods available when using the Playwright driver.
Access via runtime.page.locator(...) after launching a Playwright runtime.
How these methods work over HTTP
Every method below is a remote call. The SDK translates it into a structured step sent to a single endpoint:
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.
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.
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.
clear(options?)
Clears the input field.
Waits for actionability checks, focuses the element, clears it, and triggers an input event.
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.
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.
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.
hover(options?)
Hovers over the element.
Waits for actionability checks, scrolls element into view, and moves mouse to the center of the element.
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.
focus(options?)
Focuses the element.
blur(options?)
Removes focus from the element.
check(options?)
Checks a checkbox or radio button.
If already checked, this method does nothing.
uncheck(options?)
Unchecks a checkbox.
If already unchecked, this method does nothing.
setChecked(checked, options?)
Sets the checked state of a checkbox or radio button.
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.
Returns string[]
selectText(options?)
Selects all text content of the element.
This method waits for actionability checks, then focuses the element and selects all text content.
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.
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.
scrollIntoViewIfNeeded(options?)
Scrolls the element into view if not already visible.
Uses IntersectionObserver to determine if element is already visible.
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.
highlight()
Highlights the element on screen (for debugging).
Useful for debugging during test development. Not recommended for production tests.
Queries
count()
Returns the number of elements matching this locator.
For assertions, prefer expect(locator).toHaveCount() to avoid flakiness.
Returns number
first()
Returns locator to the first matching element.
Returns RemotePlaywrightLocator
last()
Returns locator to the last matching element.
Returns RemotePlaywrightLocator
nth(index)
Returns locator to the nth matching element.
Index is zero-based. Negative indices count from the end (-1 is last).
Returns RemotePlaywrightLocator
locator(selectorOrLocator, options?)
Creates a locator matching descendants of this element.
Accepts CSS, XPath, or text selectors. Can also accept another locator.
Returns RemotePlaywrightLocator
filter(options?)
Narrows the locator with additional filters.
Supports has, hasNot, hasText, hasNotText, and visible options. Multiple filters can be chained.
Returns RemotePlaywrightLocator
and(locator)
Creates a locator that matches both this locator AND the argument.
Both conditions must be satisfied for an element to match.
Returns RemotePlaywrightLocator
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.
Returns RemotePlaywrightLocator
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.
Returns RemotePlaywrightLocator[]
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.
Returns RemotePlaywrightLocator
getByText(text, options?)
Locates elements containing the specified text.
Matches case-insensitively by default. Use exact: true for exact match.
Returns RemotePlaywrightLocator
getByLabel(text, options?)
Locates form elements by their associated label text.
Matches <label> text, aria-label, or aria-labelledby.
Returns RemotePlaywrightLocator
getByPlaceholder(text, options?)
Locates input elements by their placeholder text.
Returns RemotePlaywrightLocator
getByAltText(text, options?)
Locates elements by their alt attribute (typically images).
Returns RemotePlaywrightLocator
getByTitle(text, options?)
Locates elements by their title attribute.
Returns RemotePlaywrightLocator
getByTestId(testId)
Locates elements by their test ID attribute.
Default attribute is data-testid. Can be configured via selectors.setTestIdAttribute().
Returns RemotePlaywrightLocator
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.
Returns RemotePlaywrightFrameLocator
frameLocator(selector)
Returns a FrameLocator for an iframe within this element.
Use to interact with content inside iframes.
Returns RemotePlaywrightFrameLocator
page()
Returns the Page that this locator belongs to.
Returns RemotePlaywrightPage
Content
innerHTML(options?)
Returns the innerHTML of the element.
Returns string
innerText(options?)
Returns the innerText of the element.
For assertions, prefer expect(locator).toHaveText() with useInnerText option.
Returns string
textContent(options?)
Returns the textContent of the element.
For assertions, prefer expect(locator).toHaveText().
Returns string \| null
allInnerTexts()
Returns an array of innerText values for all matching elements.
For assertions, prefer expect(locator).toHaveText() with useInnerText option.
Returns string[]
allTextContents()
Returns an array of textContent values for all matching elements.
For assertions, prefer expect(locator).toHaveText().
Returns string[]
getAttribute(name, options?)
Returns the attribute value of the element.
Returns string \| null
inputValue(options?)
Returns the input value for <input>, <textarea>, or <select> elements.
Returns string
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.
Returns PlaywrightBoundingBox \| null
State Checks
isVisible(options?)
Returns whether the element is visible.
Does not wait for element to appear. For assertions, prefer expect(locator).toBeVisible().
Returns boolean
isHidden(options?)
Returns whether the element is hidden.
Opposite of isVisible(). For assertions, prefer expect(locator).toBeHidden().
Returns boolean
isEnabled(options?)
Returns whether the element is enabled.
For assertions, prefer expect(locator).toBeEnabled().
Returns boolean
isDisabled(options?)
Returns whether the element is disabled.
For assertions, prefer expect(locator).toBeDisabled().
Returns boolean
isChecked(options?)
Returns whether a checkbox or radio is checked.
For assertions, prefer expect(locator).toBeChecked().
Returns boolean
isEditable(options?)
Returns whether the element is editable.
For assertions, prefer expect(locator).toBeEditable().
Returns boolean
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’.
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.
Returns Buffer
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.
Returns R
evaluateAll(pageFunction, arg?)
Evaluates a function with all matching elements as first argument.
Does not wait for elements - returns empty array if none match.
Returns R
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.
Returns unknown
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.
Returns RemotePlaywrightElementHandle
elementHandles()
Resolves to all ElementHandles matching this locator.
Returns an empty array if no elements match.
Returns RemotePlaywrightElementHandle[]

