Playwright · Junior · Question 14 of 75

Which locator does Playwright recommend first for a button?

Show the answer

Correct answer: page.getByRole('button', { name: 'Save' })

Explanation

Role locators reflect how users and assistive tech see the page. They survive markup and class changes better than CSS or XPath chains.

Further reading

Problem with a question

Playwright · Junior · question 14

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