Playwright · Junior · Question 23 of 75
How do you find a product card that contains the text "Laptop"?
- 1
page.getByTestId('card').filter({ hasText: 'Laptop' }) - 2
page.getByTestId('card').withText('Laptop', true) - 3
page.getByTestId('card').where({ 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.