Playwright · Junior · Question 24 of 75

What does chaining locators like this do?

page.getByRole("dialog").getByRole("button", { name: "OK" })
Show the answer

Correct answer: Searches for the button only inside the dialog

Explanation

Chaining scopes the search to the parent locator. It avoids matching an "OK" button elsewhere on the page.

Further reading

Problem with a question

Playwright · Junior · question 24

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