Safari exposes web content through the Accessibility tree, allowing you to interact with web pages using the same commands as native apps.
Overview
Safari is unique among browsers because it exposes web content as Accessibility nodes. This means you can use agent-native to:- Navigate to URLs
- Click links and buttons
- Fill forms
- Read page content
- Interact with web applications
Core workflow
1
Open Safari
2
Navigate to URL
Safari’s address bar is an
AXTextField. Find it and fill it:3
Re-snapshot to see page content
AXButton, AXLink, AXTextField, etc.4
Interact with page elements
Safari’s Accessibility tree
Safari represents web pages with semantic HTML roles mapped to AX roles:
See AXEngine.swift:196-234 for how nodes are built from AX attributes.
Navigation patterns
Entering URLs
Navigating back/forward
Reloading pages
Opening new tabs
Form filling
Text inputs
Checkboxes
Dropdowns/Select elements
Radio buttons
Submit buttons
Example: GitHub login
Complete workflow for logging into GitHub:Example: Searching and clicking links
Reading page content
Get text from elements
Get page title
Check element states
Working with dynamic content
Waiting for elements
Usewait to wait for elements to appear:
Handling page loads
Re-snapshotting after interactions
Common Safari keyboard shortcuts
Best practices
Wait for page loads
Always add delays after navigation:
Use keyboard shortcuts
Shortcuts are more reliable than clicking toolbar buttons:
Check page titles
Verify navigation by checking titles:
Handle dynamic content
Use
wait for elements that load asynchronously:Troubleshooting
Web elements not appearing in snapshot
Web elements not appearing in snapshot
Possible causes:
- Page not fully loaded
- Content is in an iframe
- Elements are dynamically rendered
- Wait longer for page load:
- Check full tree without
-iflag: - Try increasing depth:
Address bar not found
Address bar not found
Solutions:
- Use keyboard shortcut instead:
- Search for “Address” or “Search”:
Form submission not working
Form submission not working
Possible causes:
- Submit button requires specific event
- Form validation failing
- Try pressing Enter instead of clicking:
- Check if validation errors appear:
- Verify all required fields are filled
Clicking wrong element
Clicking wrong element
Problem: Multiple elements with similar titles.Solutions:
- Use more specific filters:
- Use index to select specific match:
- Inspect elements to verify:
Page content not updating
Page content not updating
Problem: Snapshot shows old content after interaction.Cause: Need to wait for page update.Solutions:
- Add delay before re-snapshotting:
- Use
waitfor specific element:
Limitations
For complex web automation, consider:- Using simpler, more accessible websites
- Combining with screenshots for visual verification
- Using keyboard shortcuts when AX tree is sparse
- Testing with Safari’s Accessibility Inspector first
Next steps
Electron apps
Automate Slack, Discord, and VS Code
System Settings
Configure macOS system settings
Troubleshooting
Fix common issues and errors
API reference
Explore all commands