Playwright · Junior · Question 23 of 75

How do you find a product card that contains the text "Laptop"?

Show the answer

Correct answer: page.getByTestId('card').filter({ hasText: 'Laptop' })

Explanation

filter({ hasText }) keeps only matches containing the text. filter({ has: locator }) keeps those containing a matching child element.

Further reading

Problem with a question

Playwright · Junior · question 23

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