Playwright · Junior · Question 15 of 75

Which locator is best for an input that has a <label>?

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.

Further reading

Problem with a question

Playwright · Junior · question 15

Test yourself

Take the Playwright · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz