select, lastElement
Grabs an element without touching the device, for reading values or chaining assertions.
Functions
| function | description |
|---|---|
select(sel, requireVisible:waitSeconds:scroll:maxSwipes:) |
Grabs an element. Unlike exist, this is not an assertion — it does not appear as a verification step in the report. Used as the starting point for reading a value (.text / .value / .id) or for chaining an assertion. If the element cannot be grabbed, it does not fail — it returns an empty element instead, so callers branch on .isEmpty / .isNotEmpty. Use exist when you need to assert the element is there. requireVisible: false skips the visibility check entirely. When the element is judged not visible, the screen is captured once more before deciding (so a single frame taken mid-transition does not return an empty element). |
select(sel, scroll: .noScroll) |
Grabs from the current screen only, even inside a withScrollDown { } block. |
select(sel).tap(holdSeconds:maxGestureSeconds:settle:) |
Taps the grabbed element. It resolves the grabbed selector again, so it behaves like tap(sel). An element grabbed by findImage / findImages is tapped at the center of the found frame, by coordinates (an image element that was not found fails). |
select(sel).type(text, replace:settle:waitSeconds:) |
Types into the grabbed element. It resolves the grabbed selector again, so it behaves like type(sel, text). It fails on an element that was not found. Elements grabbed by findImage / findImages cannot be typed into (call .tap() first, then type(text)). To just type, type(sel, text) is enough. |
lastElement |
The most recently grabbed element (no arguments). Any command that resolves a single element — select / exist / tap / type / waitForDisplay / text and value assertions — replaces it when it succeeds. It holds the value at the moment it was grabbed; scrolling or tapping afterwards does not refresh it. |
Every command accepts a typed selector Sel in place of a selector string (typed selector).
Example
select("#btn_ok").textIs("OK")
let e = select("#txt_total")
if e.isNotEmpty {
// element was found
}
Reading a value out of a grabbed element (.text, .value, .id) is covered in
reading values.
Notes
selectnever fails a scenario by itself — a missing element becomes an empty element, not a thrown error. Only the commands you chain onto it (.textIs(...), etc.) can fail the step.- On Android,
selectis refused while the app under test is not in front (the home screen, another app or the app switcher is showing): the step waits up to its usual wait for the app to come back and then fails instead of returning an empty element, asnotExistandcountIs(0)do (otherwise the empty element would be read as "the element is absent"). Bring the app back first withlaunchApp()ortapAppIcon()(see navigation). lastElementis empty at the start of eachscene, is overwritten with an empty element when a command fails to grab, and is empty (with a warning) if nothing has been grabbed yet.- When
waitSeconds:is omitted,selectkeeps looking for the element up to the run profile's default wait (defaultTimeout, 5 s by default) before returning an empty element — unlike actions such astap, which retry for about 0.7 s. To look at the current screen once and branch, writeselect(sel, waitSeconds: 0).