Atlas › 13 Browser Automation with Playwright › Advanced Locators☰ Read as one page
Advanced Locators
8.1OverviewReal-world applications have complex UIs: tables with hundreds of rows, nested components, dynamic lists, iframes, and shadow DOM…8.2Filtering Locatorsfilter() narrows a locator by additional criteria — text content, child elements, or visibility.8.3Chaining LocatorsChaining scopes a locator within another locator — like finding an element inside a container.8.4Nth Element SelectionWhen multiple elements match and you need a specific one:8.5Frame LocatorsIframes are common in payment forms, third-party widgets, and legacy applications. Playwright provides frameLocator() to scope into frames.8.6Shadow DOMPlaywright pierces shadow DOM by default — unlike Selenium, where shadow DOM traversal requires JavaScript injection.8.7Locator Best Practices for Complex UIs8.8Key Takeaways- Use filter() to narrow locators by text content or child elements — more resilient than positional selectors - Chain locators to scope…