Skip to main content

Selector

Enum Selector 

Source
pub enum Selector {
    Text {
        text: Pattern,
        modifiers: Modifiers,
    },
    Id {
        id: String,
        modifiers: Modifiers,
    },
    Label {
        label: String,
        modifiers: Modifiers,
    },
    Role {
        role: Role,
        name: Option<Pattern>,
        modifiers: Modifiers,
    },
    Focused {
        focused: True,
    },
    Anchor {
        anchor: AnchorBox,
        index: IndexModifiers,
    },
    LocalizedText {
        localized_text: BTreeMap<String, String>,
        modifiers: Modifiers,
    },
    OcrText {
        ocr_text: String,
        locales: Vec<String>,
        modifiers: Modifiers,
    },
    AnchorRelative {
        anchor: Box<Selector>,
        dx: f64,
        dy: f64,
    },
    Point {
        nx: f64,
        ny: f64,
    },
    Fallback {
        fallback: Vec<Selector>,
    },
}
Expand description

Selector — 6 mutually exclusive base forms.

Each variant carries its base-shape fields and the modifier set stackable on that base. serde(untagged) ensures the JSON wire form matches the existing TS Selector wire 1:1 (no {type: "text", ...} discriminator — the presence of text / id / label / role / focused / anchor is the discriminator, mirroring TS’s isXSelector type-guards).

Variants§

§

Text

{ text: 'hello' | /^hi/, ...modifiers }

Fields

§text: Pattern

Text pattern (literal or regex).

§modifiers: Modifiers

Stacked spatial + index modifiers.

§

Id

{ id: 'btn-xyz', ...modifiers }

Fields

§id: String

Accessibility identifier (strict equal).

§modifiers: Modifiers

Stacked spatial + index modifiers.

§

Label

{ label: 'Settings', ...modifiers }

Fields

§label: String

Accessibility label (strict equal).

§modifiers: Modifiers

Stacked spatial + index modifiers.

§

Role

{ role: 'button', name?: pattern, ...modifiers }

Fields

§role: Role

Semantic role.

§name: Option<Pattern>

Optional accessible-name pattern (label / title / text scan).

§modifiers: Modifiers

Stacked spatial + index modifiers.

§

Focused

{ focused: true } — no modifiers (focus is runtime-resolved).

Fields

§focused: True

Always true on the wire. Deserialized as a discriminator.

§

Anchor

{ anchor: { ...spatial keys }, ...indexModifiers }

Fields

§anchor: AnchorBox

Spatial-only anchor sub-selectors (AnchorBox has no nth/first/last).

§index: IndexModifiers

Index pick applied after spatial filtering.

§

LocalizedText

{ localized_text: { en: "Submit", ja: "送信", es: "Enviar" }, ...modifiers } — v5.18 c1 (a11y-i18n initiative L4 layer). Per-locale text table for elements whose visible text varies across locales when no stable accessibilityIdentifier is exposed. Adapter desugars this variant to Selector::Text { text: <picked-by-current-locale> } before passing to the resolver — the resolver itself never sees LocalizedText (unreachable arm in resolver match). Locale is read from the last launchApp -AppleLanguages argument the adapter parsed; fallback to “en” when current locale not in table (or no launchApp seen yet).

Fields

§localized_text: BTreeMap<String, String>

Locale code → text mapping. Locale codes are bare BCP-47 language subtag (e.g. “en”, “ja”, “es”), matching the (xx) form inside -AppleLanguages "(xx)". BTreeMap for stable iteration

  • deterministic debug / test output.
§modifiers: Modifiers

Stacked spatial + index modifiers.

§

OcrText

{ ocr_text: "Submit", locales: ["en"], ...modifiers } — v5.19 c1 (a11y-i18n initiative L5 layer). Apple Vision OCR keyword over the current XCUIScreen screenshot. For elements with no stable accessibilityIdentifier AND no a11y label (custom-drawn UI / 3rd party libs that bypass UIAccessibility). Adapter handles dispatch directly (find_by_text_ocr → IOHID synthesize at frame center), bypassing the standard resolver pipeline — OcrText never reaches resolver match arms. Locales are BCP-47 subtags; empty array defaults to adapter’s last_locale (which itself defaults to “en”).

Fields

§ocr_text: String

Substring keyword to OCR-match against text observations. Case-insensitive substring match on topCandidates(1) of each VNRecognizedTextObservation.

§locales: Vec<String>

BCP-47 language subtags for Apple Vision recognitionLanguages (e.g. ["en"] / ["ja"]). Empty = adapter fills from last_locale.

§modifiers: Modifiers

Stacked spatial + index modifiers (mostly nth for ambiguity disambiguation when multiple text observations match).

§

AnchorRelative

{ anchored: { anchor: <selector>, dx: -0.15, dy: 0 } } — v5.20 c1 (a11y-i18n initiative L6 layer). Anchor-relative coord for icon-only / pure-graphic elements (~15-20% of “lib without a11y” scenarios) where no sense layer can locate the target directly, but a STABLE nearby element (status label, header text, etc.) is sense-able.

Resolution: adapter finds anchor via host-resolve → anchor center in normalized [0, 1] viewport coords → add (dx, dy) shift (also normalized — dx: 0.15 = 15% of screen width to the right) → clamp to [0, 1] → IOHID synthesize via tap_at_norm_coord.

Compared to Selector::Anchor (spatial-relation chain — “find a node near/below/leftOf <anchor>”), AnchorRelative is an escape hatch family (§9 #3 sibling to tap_at_coord) — the target itself has no a11y form, only the anchor does. Adapter dispatches directly (find_norm_coord(anchor) → tap_at_coord), bypassing resolver.

Fields

§anchor: Box<Selector>

Anchor selector — any other Selector form (Id / Text / Role / LocalizedText / etc.). Must resolve to exactly one node; adapter uses centroid.

§dx: f64

X shift from anchor center in viewport-normalized space (dx: 0.15 = 15% of screen width to the right; dx: -0.15 = 15% to the left).

§dy: f64

Y shift from anchor center in viewport-normalized space (dy: 0.05 = 5% of screen height downward).

§

Point

{ point: [0.5, 0.9] } — v5.20 c2 (a11y-i18n initiative L7 layer, last-resort within fallback chain). Direct viewport-normalized coord. Equivalent to Step::TapAtPoint for standalone use, but expressed as a Selector for uniform composition inside Selector::Fallback { chain: Vec<Selector> }. Adapter dispatches directly via tap_at_coord; never reaches resolver.

Fields

§nx: f64

X in viewport-normalized [0, 1].

§ny: f64

Y in viewport-normalized [0, 1].

§

Fallback

{ fallback: [<selector1>, <selector2>, ...] } — v5.20 c2 (a11y-i18n initiative L7 layer). Sequential resolution chain — adapter tries each sub-selector in order; first hit wins. Misses are recorded for AI-readable error report (sense_layer / missing_id_hint / suggested_fixes). On all-miss, surfaces ElementNotFound with a chain-trace hint listing every attempted layer.

Composes L1-L7 into a single tapOn — typical pattern:

tapOn:
  fallback:
    - { id: "submit-btn" }                                # L1
    - { localized_text: { en: "Submit", ja: "送信" } }   # L4
    - { ocrText: "Submit" }                                # L5
    - { anchored: { anchor: { id: "form-area" }, dx: 0.0, dy: 0.05 } }  # L6
    - { point: [0.5, 0.9] }                                # L7

Adapter dispatches each sub-selector through the standard run_tap path; chain element types are limited only by what run_tap can dispatch (any concrete Selector variant). Nesting Fallback inside Fallback is allowed but discouraged (no defined precedence beyond outer-then-inner).

Fields

§fallback: Vec<Selector>

Sequential chain of sub-selectors. First hit wins.

Trait Implementations§

Source§

impl Clone for Selector

Source§

fn clone(&self) -> Selector

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Selector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Selector

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Selector

Source§

fn eq(&self, other: &Selector) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Selector

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Selector

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.