Docs
API 1.39
Status
DSL

Targets

How a step or a condition names an element.

A target is a CSS selector string, or an object with one locator key (or candidates, an ordered list of them) and the modifiers below. Locators explains how candidates are ranked and healed.

KeyTypeDescription
candidatesobject[]An ordered list of single-locator targets, tried in order until one matches exactly one element. A target with candidates carries no other locator key (lint E005); lint warns W002 when every candidate is structural or positional.
cssstringA CSS selector. >>> crosses into a shadow root.
exactbooleanWhether name or text must match exactly rather than as a substring.
framestring[]The chain of <iframe> selectors from the top document to the frame the target is in. Cross-origin frames work in browser tiers only.
namestringThe accessible name that qualifies a role locator, such as the label of a button.
nthintegerPicks one of several matches, 0-based. Without it, a locator that matches more than one element fails with target_ambiguous.
rolestringAn ARIA role such as button or link, usually with name.
testidstringThe value of the element's test id attribute, such as data-testid. The most stable locator.
textstringText the element shows; qualify with exact.
xpathstringAn XPath expression. A structural path breaks with the next redesign, so it ranks low (20) for lint and healing.

Was this page helpful?