Overview
Scrolls the parent container to bring a specific element into view. This ensures the target element is visible on screen, making it ready for interaction.Syntax
Parameters
Element reference from snapshot (element to scroll into view)
Response
Response Fields
The action performed (
scroll_to)The element reference that was scrolled into view
AX-First Strategy
The scroll-to command:- Uses
kAXScrollToVisibleActionon the element via accessibility - Calculates element position and scrolls parent container
- Falls back to mouse wheel events if AX fails
- Verifies element bounds are within visible area
Usage Examples
Scroll List Item Into View
Scroll and Interact
Scroll to Form Field
Ensure Visibility Before Action
When to Use Scroll-To
Usescroll-to when:
- Element is in snapshot but may be off-screen
- You need to interact with an element that’s not visible
- Working with long lists or scrollable containers
- Ensuring element visibility before click/type
- Element is already visible
- Clicking elements in current viewport
- Element doesn’t have a parent scroll area
Scroll-To vs Scroll
| Command | Target | Use Case |
|---|---|---|
scroll-to | Specific element by ref | Make element visible |
scroll | Direction + amount | Explore content, relative movement |
Common Use Cases
- Long Lists: Scroll to items deep in file/folder lists
- Form Submissions: Scroll to submit button at bottom
- Search Results: Scroll to specific search result
- Tree Navigation: Reveal nested tree items
- Settings Panels: Scroll to specific setting in long panel
Element Visibility
Afterscroll-to, the element:
- Is within the visible bounds of its scroll area
- May be at top, middle, or bottom of viewport (platform-dependent)
- Is ready for interaction (click, type, etc.)
- May have different coordinates than before
Error Cases
| Error Code | Cause | Recovery |
|---|---|---|
ELEMENT_NOT_FOUND | Ref doesn’t exist in current refmap | Run snapshot to refresh |
STALE_REF | Element no longer matches saved ref | Run snapshot and use new ref |
ACTION_FAILED | Element has no scrollable parent | Element may already be visible |
ACTION_NOT_SUPPORTED | Platform doesn’t support scroll-to | Use scroll with direction |
Verifying Visibility
Scroll-To + Snapshot Pattern
Performance
- Faster than multiple directional
scrollcommands - Single operation to reach target
- Platform-optimized scrolling
- May trigger smooth scroll animation
Automatic Scrolling
Some commands implicitly scroll to element before interacting:| Command | Auto-Scrolls |
|---|---|
click | Sometimes (platform-dependent) |
type | No |
set-value | No |
scroll-to first:
Nested Scrolling
For nested scroll areas:Notes
- Element must exist in current snapshot (have a ref)
- Scrolls parent container, not the element itself
- Final position may vary (top/middle/bottom of viewport)
- Some apps animate scroll; consider adding
wait - Always snapshot after scroll-to to capture new state
- Use
is @ref visibleto verify visibility - More efficient than searching with multiple
scrollcommands - Does not change focus or selection