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" });

Explanation

filter also supports has, hasNot and hasNotText.

Further reading

Problem with a question

Testing · Middle · question 45

Test yourself

Take the Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz