Typed Selector (Sel)
A selector expression is a single string, so a typo can't be caught by the compiler — only
by the runtime syntax check. Sel is a type-checked, autocompleted way to write the same
selector notation, offered alongside the string form (not a replacement for it).
Examples
tap(.id("login_btn")) // #login_btn
tap(.id("login_btn").or(.text("Log In"))) // #login_btn||Log In
tap(.id("list").find(.type(.cell).nth(2))) // #list >> .cell[2]
tap(.text("Notification").right(.switch)) // Notification:rightSwitch
exist(.type(.button).text("Save", .contains)) // .button&&textContains=Save
tap(.type(.button).not(.text("Cancel"))) // .button&&text!=Cancel
Every command that takes a selector has both a String overload and a Sel overload — use
whichever reads better in a given line; they build the exact same underlying locator, so
execution, reporting, and self-healing behave identically either way.
Vocabulary
.id(_),.text(_),.value(_),.placeholder(_)— each takes an optional second argumentmode, one of.exact(the default) /.contains/.startsWith/.endsWith/.matches. Also.type(_),.checked(_),.enabled(_),.nth(_)(1-origin ordinal).- Compose with
.or(_)(union) and.find(_)(scope into a descendant). - Exclude with
.not(_)— the typed form of the string notation'sattr!=value/!value. Pair it with a positive condition, exactly as the string form requires: a clause of only a negation matches containers and layout nodes too. If the argument itself contains.or(_), every alternative is excluded. - Relative:
.right(_),.left(_),.above(_),.below(_)— take an optionalmatching:filter andnth:(nearest-first ordinal), mirroring the string form's relative selector. - Type names:
.button,.staticText,.textField,.secureTextField,.switch, plus the aliases.input(textField or secureTextField) and.widget(the five above)..cell,.imageand.clickablealso exist, but they are real type names rather than aliases, and some OSes never report them. Anything outside this vocabulary is.custom("...").
Filter methods (.text, .type, .nth, …) always apply to the current target: before a
relative step that's the anchor, after a relative step that's the resolved candidate.
Notes
- A misspelled member name (
.buton) is a compile error inSel, unlike the string form's"buton"(which is a runtime syntax error at best, or silently a literal label at worst). scrollFrame:stays string-only — there is noSeloverload for that one argument, even on commands that otherwise have a fullSeloverload.- Do not narrow an element that has an #id by type (
#pager_main, not.collectionView#pager_main). On iOS the same element can report a different type in the XCUITest bridge (what MCPft_*tools always use) and in inapp-boost mode (a SwiftUITabView(.page)iscollectionViewin XCUITest andotherin inapp-boost). A type filter then passes through MCP and matches nothing in the real run. When the same id matches several elements, pick with[n]or an ancestor. - Generated code (from agent-driven scenario authoring) writes the string form by default.
Selis there for people who prefer to write it by hand.
See Selector expression for the full notation this maps to.