Modern QA2026Locator Robustness Hierarchy — tiles
Log inJoin
107 / 168 · 01 Agent Skills for Browser Automation · Self-Healing Strategies for Agent-Driven Tests← prev⊞ allnext →☰ Read as one page

14.7Locator Robustness Hierarchy

The agent interacts via snapshot refs at runtime, but the tests the generator writes (and the patches the healer makes) are .spec.ts files with real locators — so locator robustness still matters. From most to least robust:

Strategy Example Resilience Readability
Role + accessible name getByRole('button', { name: 'Submit' }) Highest High
data-testid getByTestId('submit') Highest High
ARIA label [aria-label="Submit form"] High High
Semantic HTML form button[type=submit] Medium Medium
Class name .btn-submit Medium Medium
ID #submit-btn Medium High
CSS path div > form > div:nth-child(3) > button Lowest Lowest

Recommendation for AI-driven tests: role + accessible name first — it's the same vocabulary the snapshots and the agents speak, so healed tests stay consistent with how they were explored. Use data-testid where accessible names are unstable (requires collaboration with developers).