Skip to main content

Function: byDataTestId()

byDataTestId(id, relativeTo): CssLocator

Defined in: packages/core/src/locators/byDataTestId.ts:28

Locate an element by its data-testid attribute.

When an array of ids is provided, they will be chained as descendant selectors in the resulting locator.

Parameters​

id​

Single id or an array of ids to match against the data-testid attribute.

string | string[]

relativeTo​

LocatorRelativePosition = 'Descendant'

How the locator is related to the current locator in a locator chain. Defaults to 'Descendant'.

Returns​

CssLocator

Example​

const submitButton = byDataTestId('submit');
const itemLabel = byDataTestId(['list', 'item-label']);