Skip to main content
Locator queries methods for the Playwright driver.

count

Returns the number of elements matching this locator.
For assertions, prefer expect(locator).toHaveCount() to avoid flakiness.
Upstream docs
result
number
Return value
await locator.count();

first

Returns locator to the first matching element. Upstream docs
result
RemotePlaywrightLocator
Return value
await locator.first();

last

Returns locator to the last matching element. Upstream docs
result
RemotePlaywrightLocator
Return value
await locator.last();

nth

Returns locator to the nth matching element.
Index is zero-based. Negative indices count from the end (-1 is last).
Upstream docs
index
number
required
Zero-based index
result
RemotePlaywrightLocator
Return value
await locator.nth(0);

locator

Creates a locator matching descendants of this element.
Accepts CSS, XPath, or text selectors. Can also accept another locator.
Upstream docs
selectorOrLocator
string | RemotePlaywrightLocator
required
Selector or locator to match descendants
options
PlaywrightLocatorOptions
result
RemotePlaywrightLocator
Return value
await locator.locator(/* string | RemotePlaywrightLocator */);

filter

Narrows the locator with additional filters.
Supports has, hasNot, hasText, hasNotText, and visible options. Multiple filters can be chained.
Upstream docs
options
PlaywrightLocatorFilterOptions
result
RemotePlaywrightLocator
Return value
await locator.filter();

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.
Upstream docs
result
RemotePlaywrightLocator[]
Return value
await locator.all();

getByRole

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.
Upstream docs
role
PlaywrightAriaRole
required
ARIA role to match
options
PlaywrightGetByRoleOptions
result
RemotePlaywrightLocator
Return value
await locator.getByRole(/* PlaywrightAriaRole */);

getByText

Locates elements containing the specified text.
Matches case-insensitively by default. Use exact: true for exact match.
Upstream docs
text
string | RegExp
required
Text or pattern to match
options
PlaywrightGetByTextOptions
result
RemotePlaywrightLocator
Return value
await locator.getByText(/* string | RegExp */);

getByLabel

Locates form elements by their associated label text.
Matches <label> text, aria-label, or aria-labelledby.
Upstream docs
text
string | RegExp
required
Label text or pattern
options
PlaywrightGetByLabelOptions
result
RemotePlaywrightLocator
Return value
await locator.getByLabel(/* string | RegExp */);

getByPlaceholder

Locates input elements by their placeholder text. Upstream docs
text
string | RegExp
required
Placeholder text or pattern
options
PlaywrightGetByPlaceholderOptions
result
RemotePlaywrightLocator
Return value
await locator.getByPlaceholder(/* string | RegExp */);

getByAltText

Locates elements by their alt attribute (typically images). Upstream docs
text
string | RegExp
required
Alt text or pattern
options
PlaywrightGetByAltTextOptions
result
RemotePlaywrightLocator
Return value
await locator.getByAltText(/* string | RegExp */);

getByTitle

Locates elements by their title attribute. Upstream docs
text
string | RegExp
required
Title attribute text or pattern
options
PlaywrightGetByTitleOptions
result
RemotePlaywrightLocator
Return value
await locator.getByTitle(/* string | RegExp */);

getByTestId

Locates elements by their test ID attribute.
Default attribute is data-testid. Can be configured via selectors.setTestIdAttribute().
Upstream docs
testId
string | RegExp
required
Test ID value or pattern
result
RemotePlaywrightLocator
Return value
await locator.getByTestId(/* string | RegExp */);

frameLocator

Returns a FrameLocator for an iframe within this element.
Use to interact with content inside iframes.
Upstream docs
selector
string
required
CSS selector for iframe
result
RemotePlaywrightFrameLocator
Return value
await locator.frameLocator('...');