Playwright · Junior · Question 71 of 75

Why is getByRole('link', { name: 'Docs' }) better than locator('a:nth-child(3)')?

Show the answer

Correct answer: It doesn't depend on element order or markup

Explanation

Positional selectors break when someone adds a link. A role and accessible name describe what the user sees.

Further reading

Problem with a question

Playwright · Junior · question 71

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