scroll (scrollTo, scrollDown, withScrollDown, scrollFrame, ...)

in Japanese(日本語)

Content-based scrolling: search for an element while scrolling, scroll a fixed amount, or scroll to an edge.

Functions

function description
scrollTo(sel, direction: .down, scrollFrame:, startMarginRatio:, endMarginRatio:, containerInference:, settle:, waitSeconds:, maxSwipes: 8) Scrolls until the element is found (found = success; does not tap it). It searches only in the direction: given. If you write waitSeconds:, it does not declare the end for that many seconds even after the content stops moving at the end (the list is not shown yet, still a skeleton, or a "Retry" or similar appears late at the bottom). The seconds count from the start of the search if nothing has moved, or from when it reached the end if the content moved first. While waiting it only re-reads the screen without scrolling, so it does not use up maxSwipes: (if the content changes, the search continues). Without waitSeconds:, it declares the end after two rounds with no movement. maxSwipes: caps the number of swipes, but a swipe that moved the content less than the length of the area being scrolled counts only for the part it moved (so a path with shorter swipes searches the same distance; at most twice maxSwipes: swipes are sent). Only if the content moved in that direction first, and the search then reaches the end (or uses up maxSwipes:) without finding the element, it steps back in small, slow drags (up to 8) to pick up a row the scrolling skipped over. If the list was already at its end and nothing moved at all, it does not step back and fails without searching the other side (a plain label with no # that matches nothing, while an element with that text as its id is on the screen, fails before scrolling and tells you to write #…); it does not step back either when the screen the search started on belongs to another app than the one launched. If nothing moved while the soft keyboard covered the bottom of the scrolled area, it closes the keyboard by a means with no side effect (the same as for tap; Enter is never pressed) and starts the search over once.
scrollDown(scrollFrame:, startMarginRatio:, endMarginRatio:, repeat: 1, settle:) / scrollUp / scrollRight / scrollLeft Scrolls one screenful (repeat: times to repeat). If nothing on the screen moved, it still passes with the note scroll-moved-nothing (the list may already be at its end, or the swipe started outside it — pass scrollFrame: to swipe inside a specific list; when you already passed scrollFrame:, the note only says the list may be at its end).
scrollToBottom(scrollFrame:, startMarginRatio:, endMarginRatio:, settle:, maxSwipes: 50) / scrollToTop / scrollToRightEdge / scrollToLeftEdge Scrolls to the edge — until the screen stops changing. maxSwipes is a runaway guard; hitting it leaves a note on the step.
withScrollDown { … } / withScrollUp / withScrollRight / withScrollLeft Makes every tap / type / clearInput / select / exist / notExist / findImage / existImage / hold inside the block search by scrolling (an explicit scroll: on a command still wins). notExist changes meaning inside the block — it fails as soon as the element turns up while scrolling.
withoutScroll { … } Cancels an outer withScroll* — commands inside resolve against the current screen only.
withoutContainerInference { … } Disables the container-inference corrections (below) for every command inside the block.
scroll: .noScroll (an argument of tap / type / clearInput / select / exist / notExist / findImage / existImage / hold) Skips scrolling for this one command even inside a withScroll* block (it resolves against the current screen only). Leaving the argument out follows the direction of the block.

settle: false skips this command's post-action wait for the screen to settle (the next step may see a moving screen). See tap for details.

Scrolling is specified only through each command's scroll: argument. A direction (.down / .up / .right / .left) searches while scrolling that way, and .noScroll never scrolls, even inside a withScroll* block. Leaving it out follows the direction of the enclosing block (outside a block: the current screen only). There are no function-name aliases such as tapWithScrollDown or existWithoutScroll (writing one gives a compile error that shows the scroll: form).

When maxSwipes: is omitted on a command with scroll: (tap / exist / select, etc.), it swipes at most 8 times in that direction. It stops earlier once the list has reached its edge and the content no longer moves (two swipes in a row leave the screen unchanged). Before giving up, if the content had moved in that direction, it steps back the other way in smaller steps; if nothing moved at all, it does not search the other side. If the element is still not found, the command's usual handling applies (exist / tap fail, select returns an empty element); when the search stopped at the edge, the failure message says so, because raising maxSwipes will not help.

Example

tap("Settings", scroll: .down)      // scroll to find the item behind a fold, then tap it
withScrollDown {
    tap("#row_40")                  // searched for even though not written explicitly
    exist("#header", scroll: .noScroll)   // a fixed header, checked on the current screen only
}

Notes

The scrollable region: scrollFrame:

A scrollFrame: that is empty, has a syntax error, or has alternatives (|| or (a|b)) fails before anything is scrolled (the region is one container).

When scrollFrame: names a row of a list (an element that does not scroll itself) and a scrolling list holds that row, the search swipes inside that list instead (the row moves with the content). A note says so.

scrollFrame: (also startMarginRatio: / endMarginRatio:) is an argument on scroll* / scrollToBottom etc. / scrollTo, and withScroll* takes scrollFrame: alone. It names, with a selector, the region that should actually be scrolled — needed when a screen has more than one scrollable area (a fixed header plus a scrollable list, for example). Write the arguments in this order (Swift does not allow reordering them):

scrollTo("#row_40", scrollFrame: "#list_rows")

Notes left on the report

These are observations, not failures:

note meaning worth checking?
stopped at the limit of N (may not have reached the edge yet) Stopped at maxSwipes — not necessarily the actual edge Yes. Raise maxSwipes, or check whether the screen even has an edge to reach.
the screen did not settle (poll limit) The screen was still moving after a swipe (long inertia, etc.). The swipe itself was still sent. Usually not. If it appears at the same spot every run, a tap right after could land while the content is still moving — worth investigating.
fell back to XCUITest The in-app bridge could not run this scroll, so XCUITest did it. Usually not. If it happens a lot, reconsider the run profile's iosMode.

How fast an edge scroll runs

scrollToBottom etc. repeat "scroll once, then check whether the screen stopped moving." On Android, and on iOS in xcuitest mode or Compose / Flutter, one step covers about one page, so raise maxSwipes for long screens (the default maxSwipes: 50 may not reach very long documents). iOS UIKit / SwiftUI and WebView with the in-app bridge, and the Android WebView, jump straight to the edge, so they do not depend on document length. Chaining several flick* calls to go faster is not a substitute — flick has no notion of having reached the edge; see flick.

Elements that only just peek in at the edge

When the element a search finds only just peeks in at the edge it is scrolling towards, and less than a finger's width of it (44 pt / dp) is visible, fleetest slowly scrolls half the container once more before touching it. Touching such a thin strip can be taken by the screen-edge gestures (Android's back and home) or land on something else. On iOS in the default inapp-boost mode, Compose Multiplatform and Flutter scroll exactly one page per swipe, so this extra scroll does not happen there.

Container-inference corrections

tap/scrollTo etc. apply a set of corrections that rely on inferring the scroll container — clipping detection, re-grabbing a stale element, a rescue drag, coordinate correction for a partially visible element, and discarding a broken coordinate candidate. These are on by default; turn them off only when they misfire on an unusual screen layout (a custom scroll container implementation, for example). Four scopes to choose from:

scope how
whole run environment variable FT_CONTAINER_INFERENCE=off (only to isolate a problem) — overrides all three below
one command tap(sel, containerInference: false) / scrollTo(sel, containerInference: false)
a block withoutContainerInference { … } (applies to tap/exist/select and every other command inside)
the whole run profile the run profile's containerInference: false

Excluding the environment variable, precedence is: explicit argument > block context > run profile default.