Skip to content

scrollUntilVisible ​

Scroll automatically until a target element becomes visible on screen.

Scrolls the screen in a specified direction until a target element is visible.

Parameters ​

The following parameters configure the scrollUntilVisible command.

ParameterTypeDescription
elementstring or objectRequired. The selector for the element to find. To select the element, you can use any of the available selectors.
directionstring(Optional). The direction to scroll. Accepts DOWN, UP, LEFT, or RIGHT. Defaults to DOWN.
timeoutinteger(Optional). The maximum time in milliseconds to scroll while searching for the element. If the timeout is reached before the element is found, the test fails. Defaults to 30000 milliseconds.
speedinteger(Optional). The scroll speed, specified as a value from 0 to 100. Higher values result in faster scrolling. Defaults to 40.
visibilityPercentageinteger(Optional). The percentage of the element, from 0 to 100, that must be visible in the viewport for the scroll to stop. Defaults to 100.
centerElementboolean(Optional). Accepted but not applied: Astra Scout stops as soon as the element is visible enough, as set by visibilityPercentage.
maxScrollsinteger(Optional). The maximum number of scrolls. Defaults to 20. The command also stops early, with an error, when scrolling no longer moves the screen (end of the content).

INFO

By default, an element is considered visible if it is fully displayed in the viewport.

How it works ​

The command checks whether the target element is visible. If not, it swipes in the chosen direction around the center of the screen, checks again, and repeats until the element is found, the timeout or maxScrolls is reached, or the screen stops moving.

This behavior works well when the whole screen scrolls (e.g. a full-screen list). When only part of the screen is scrollable (such as a bottom sheet, a fragment, or a small widget), the swipe may miss the scrollable region. For those layouts, use a custom scroll loop. The Custom scrolling for screen fragments shows how you can do it.

Usage examples ​

The following examples demonstrate how to use the scrollUntilVisible command.

Scroll to an element with specific text ​

This example scrolls down until an element containing the text "My text" is visible.

yaml
- scrollUntilVisible:
    element: "My text"
    direction: DOWN

Scroll to an element by ID ​

This example scrolls down until a view with a matching ID becomes visible.

yaml
- scrollUntilVisible:
    element:
      id: ".*some_view_id"
    direction: DOWN