QA PRACTICE•LOCATOR LAB
Automation Lab · Playwright locators
Locator Lab
Write a resilient locator, check it against a live target, then move from roles and labels to scoped CSS and XPath.
Challenges
0/10Beginner · Role locator challenge
Prefer the accessible role
Locate the Save profile button without depending on CSS classes.
Mini lesson
Interactive elements should be located the way a user or assistive technology perceives them: by role and accessible name.
Good: page.getByRole('button', { name: 'Save profile' })
Avoid: page.locator('.btn-primary')
Live DOM target
<button data-testid="save-profile">Save profile</button>Expected answer type: Role. Enter one locator and check whether it uniquely identifies the target.
Playwright reference
Locator cheat sheet
Quick examples for choosing a resilient locator before writing your answer.