Testing · Middle · Question 45 of 75
How do you narrow a list item locator to the one that contains a text?
page.getByRole("listitem").filter({ hasText: "Product 2" }).getByRole("button", { name: "Add" });- ✓Correct answer: With
filter({ hasText })and chaining - 2With
nth(2)only - 3With an XPath
Explanation
filter also supports has, hasNot and hasNotText.