Playwright · Junior · Question 15 of 75
Which locator is best for an input that has a <label>?
- 1
page.getByText('Email') - 2
page.getByLabel('Email') - 3
page.locator('input').first()
Show the answer
Correct answer: page.getByLabel('Email')
Explanation
getByLabel finds form controls by their associated label or aria-label. It also checks the form is accessible, unlike positional selectors.