Overview
ThedeepLocator() method creates a special locator that can traverse iframe boundaries and shadow DOM using a simplified syntax. It automatically resolves the correct frame for each operation, making cross-frame interactions seamless.
Access via the page object:
Syntax
page.deepLocator()
Create a deep locator that can cross iframe and shadow DOM boundaries.Selector string with optional iframe hop notation (
>>).Supports:- CSS selectors - Standard CSS syntax
- XPath - Prefix with
xpath=or start with/ - Hop notation - Use
>>to traverse into iframes - Deep XPath - Automatically handles iframe steps in XPath
DeepLocatorDelegate - A locator-like object that resolves frames on each action.
Hop Notation
The>> operator allows you to traverse into iframes in a readable way:
>> represents an iframe to traverse into. The final segment is the target element.
Examples
Deep XPath
When using XPath,deepLocator automatically recognizes iframe steps and traverses into them:
Methods
DeepLocatorDelegate provides the same API as Locator, with automatic frame resolution:
Interaction Methods
All interaction methods fromLocator are available:
click(options?)- Click the elementfill(value)- Fill an inputtype(text, options?)- Type texthover()- Hover over elementselectOption(values)- Select dropdown optionsscrollTo(percent)- Scroll element
State Methods
isVisible()- Check visibilityisChecked()- Check checkbox stateinputValue()- Get input valuetextContent()- Get text contentinnerText()- Get visible textinnerHtml()- Get HTML content
Selection Methods
count()- Count matching elementsnth(index)- Select by indexfirst()- Get first element
Utility Methods
highlight(options?)- Highlight elementcentroid()- Get center coordinatesbackendNodeId()- Get DOM node IDsendClickEvent(options?)- Dispatch click event
Locator, but automatically resolve the correct frame before executing.
Code Examples
- Basic Iframe Traversal
- Multiple Iframes
- Deep XPath
- Element Selection
- Payment Forms
- State Checks
Comparison with Standard Locator
Standard Locator (Single Frame)
Deep Locator (Cross-Frame)
When to Use deepLocator
UsedeepLocator() when:
- Targeting elements inside iframes - Payment forms, embedded widgets, third-party content
- Working with nested iframes - Multiple levels of iframe nesting
- XPath crosses iframe boundaries - When XPath naturally includes iframe steps
- Simpler syntax preferred - Use
>>instead of manual frame switching
locator() when:
- Elements are in main frame - No iframe traversal needed
- Performance critical - Standard locator is slightly faster (no frame resolution)
- Working with frame references - You already have the frame object
Best Practices
- Use specific selectors - Make each segment unique to avoid ambiguity
- Keep hop chains short - Simpler is better for maintainability
- Name your iframes - Use IDs or classes on iframes for easier targeting
- Test incrementally - Verify each segment works before adding more
- Cache selectors - Store complex selectors in variables for reuse
- Use highlight() for debugging - Verify you’re targeting the right element
Common Patterns
Named Iframe References
Conditional Iframe Interaction
Dynamic Frame Selection
Error Handling
Deep locator operations may throw:- Element not found - Selector doesn’t match in the target frame
- Frame not found - Iframe selector doesn’t resolve
- Timeout errors - Frame or element resolution timed out
- Invalid selector - Malformed selector syntax
Advanced Usage
Combining with Page Methods
With AI-Powered Methods
Technical Details
How It Works
- Parse selector - Splits on
>>or parses XPath for iframe steps - Build frame chain - Creates FrameLocator chain for each iframe segment
- Resolve final frame - Navigates through frames to find target frame
- Create locator - Returns a locator in the correct frame context
- Lazy execution - Frame resolution happens fresh on each action
Frame Resolution
Deep locators use the internalFrameLocator and resolveLocatorWithHops logic to:
- Track frame hierarchies
- Handle OOPIF (out-of-process iframes)
- Support shadow DOM piercing
- Maintain frame references during navigation

