Playwright Patterns Reference
Complete guide to Playwright automation patterns, selectors, and best practices.
Table of Contents
- Selectors
- Wait Strategies
- Element Interactions
- Assertions
- Test Organization
- Network Interception
- Screenshots and Videos
- Debugging
- Parallel Execution
Selectors
Text Selectors
Most readable and maintainable approach when text is unique:
Role-Based Selectors
Semantic selectors based on ARIA roles:
CSS Selectors
Traditional CSS selectors for precise targeting:
XPath Selectors
For complex DOM navigation:
Data Attributes
Best practice for test-specific selectors:
Chaining Selectors
Combine selectors for precision:
Selector Best Practices
Priority order (most stable to least stable):
data-testidattributes (most stable)role=selectors (semantic, accessible)text=selectors (readable, but text may change)idattributes (stable if not dynamic)- CSS classes (less stable, may change with styling)
- XPath (fragile, avoid if possible)
Wait Strategies
Load State Waits
Essential for dynamic applications:
Element Waits
Wait for specific elements before interacting:
Timeout Waits
Fixed time delays (use sparingly):
Custom Wait Conditions
Wait for JavaScript conditions:
Auto-Waiting
Playwright automatically waits for elements to be actionable:


