Skip to main content

Locator

Learn about the standard Locator class

Overview

The deepLocator() 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
required
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
Returns: 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:
Each segment before >> 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:
The locator intelligently parses the XPath, identifies iframe boundaries, and resolves the correct frame for the final selector.

Methods

DeepLocatorDelegate provides the same API as Locator, with automatic frame resolution:

Interaction Methods

All interaction methods from Locator are available:
  • click(options?) - Click the element
  • fill(value) - Fill an input
  • type(text, options?) - Type text
  • hover() - Hover over element
  • selectOption(values) - Select dropdown options
  • scrollTo(percent) - Scroll element

State Methods

  • isVisible() - Check visibility
  • isChecked() - Check checkbox state
  • inputValue() - Get input value
  • textContent() - Get text content
  • innerText() - Get visible text
  • innerHtml() - Get HTML content

Selection Methods

  • count() - Count matching elements
  • nth(index) - Select by index
  • first() - Get first element

Utility Methods

  • highlight(options?) - Highlight element
  • centroid() - Get center coordinates
  • backendNodeId() - Get DOM node ID
  • sendClickEvent(options?) - Dispatch click event
All methods work identically to Locator, but automatically resolve the correct frame before executing.

Code Examples

Comparison with Standard Locator

Standard Locator (Single Frame)

Deep Locator (Cross-Frame)

When to Use deepLocator

Use deepLocator() when:
  1. Targeting elements inside iframes - Payment forms, embedded widgets, third-party content
  2. Working with nested iframes - Multiple levels of iframe nesting
  3. XPath crosses iframe boundaries - When XPath naturally includes iframe steps
  4. Simpler syntax preferred - Use >> instead of manual frame switching
Use standard locator() when:
  1. Elements are in main frame - No iframe traversal needed
  2. Performance critical - Standard locator is slightly faster (no frame resolution)
  3. Working with frame references - You already have the frame object

Best Practices

  1. Use specific selectors - Make each segment unique to avoid ambiguity
  2. Keep hop chains short - Simpler is better for maintainability
  3. Name your iframes - Use IDs or classes on iframes for easier targeting
  4. Test incrementally - Verify each segment works before adding more
  5. Cache selectors - Store complex selectors in variables for reuse
  6. 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
Handle errors appropriately:

Advanced Usage

Combining with Page Methods

With AI-Powered Methods

Technical Details

How It Works

  1. Parse selector - Splits on >> or parses XPath for iframe steps
  2. Build frame chain - Creates FrameLocator chain for each iframe segment
  3. Resolve final frame - Navigates through frames to find target frame
  4. Create locator - Returns a locator in the correct frame context
  5. Lazy execution - Frame resolution happens fresh on each action

Frame Resolution

Deep locators use the internal FrameLocator and resolveLocatorWithHops logic to:
  • Track frame hierarchies
  • Handle OOPIF (out-of-process iframes)
  • Support shadow DOM piercing
  • Maintain frame references during navigation

Type Definitions