Testing · Junior · Question 62 of 78
What is the recommended way to find a button in Playwright?
- ✓Correct answer:
page.getByRole("button", { name: "Sign in" }) - 2
page.locator("#app > div:nth-child(3) > button") - 3
page.locator("xpath=//button[3]")
Explanation
User-facing locators survive markup changes; long CSS and XPath chains break on any refactor.