← Prompts
Reference / Understand Agent Rules (steipete)
Patterns and best practices for automating Safari browser interactions for web UI automation and testing
Patterns and best practices for automating Safari browser interactions for web UI automation and testing
# Safari Automation Guide
This guide captures hard-won lessons from automating Safari interactions, particularly for web UI automation and testing.
## Key Concepts
### Managing Safari Windows and Tabs
**Objective:** Reliably direct Safari to specific URLs in a predictable way, preferably using a single, consistent browser window and tab.
**Recommended Approach:**
```applescript
tell application "Safari"
activate
delay 0.2 -- Allow Safari to become the frontmost application
if (count of windows) is 0 then
-- No Safari windows are open, so create a new one.
make new document with properties {URL:"http://example.com"}
else
-- Safari has windows open; use the frontmost one.
tell front window
set targetTab to missing value
try
-- Check if a tab for the target URL is already open
set targetTab to (first tab whose URL starts with "http://example.com")Sign in to view the full prompt.
Sign InClassification
Reference Documentation, cheatsheets, setup guides
Reference Understand
Explain or analyzeScope Project
This codebase Manual Manually placed / Persistent