Selector

@Serializable
sealed interface Selector

Represents an intent query used to locate target UI nodes in a Compose Multiplatform view tree.

Selectors are passed to test scope methods (such as click(), input(), waitFor(), and assertVisible()) to resolve specific UI nodes across platforms.

Types of Selectors

  • Auto: Checks explicit testTag first, falling back to visible text matching. Created via auto.

  • Tag: Strictly matches explicit testTag properties. Created via tag.

  • Text: Strictly matches visible text substrings. Created via text.

Indexing Constraints

When multiple UI elements match a query, use indexing functions:

  • first: Picks the first visible match (index 0).

  • last: Picks the last visible match (index -1).

  • atIndex: Picks an explicit 0-indexed position.

Example Usage

// Automatic matching (tag first, then text)
click("Submit")
click(auto("Submit"))

// Exact testTag matching
click(tag("login_button"))

// Target the 2nd matching element
click(text("Delete").atIndex(1))

See also

Inheritors

Types

Link copied to clipboard
@Serializable
@SerialName(value = "auto")
data class Auto(val raw: String, val index: Int? = null) : Selector

Selector that attempts to match by explicit Compose testTag first, falling back to matching by visible text substring if no matching tag is found.

Link copied to clipboard
@Serializable
@SerialName(value = "tag")
data class Tag(val value: String, val index: Int? = null) : Selector

Selector that strictly matches nodes with the exact testTag value specified.

Link copied to clipboard
@Serializable
@SerialName(value = "text")
data class Text(val value: String, val index: Int? = null) : Selector

Selector that strictly matches nodes containing the specified visible text value.

Properties

Link copied to clipboard
abstract val index: Int?

Optional 0-indexed constraint to pick a specific node if multiple match the query.

Link copied to clipboard
abstract val raw: String

The raw query string or value used for matching.

Functions

Link copied to clipboard

Returns a copy of this Selector constrained to target the element at the specified 0-indexed position index.

Link copied to clipboard

Returns a copy of this Selector constrained to target the first matching element (index 0).

Link copied to clipboard

Returns a copy of this Selector constrained to target the last matching element (index -1).