Locator Chaining and Filtering
Playwright locators can be chained to narrow down results:
locator.locator(selector)— find within an already-located elementlocator.filter({ hasText: 'text' })— filter by text content
On the Links page, links are organized in sections.
Task:
- Navigate to
https://testkru.com/Elements/Links - Start from a
page.locator()that matches everyaelement - Narrow it to the link whose text contains "Google" with
.filter()and thehasTextoption - Print its text with
textContent()and itshrefwithgetAttribute()
Expected output:
Text: Visit Google Website Href: https://www.google.com
TestKru