Skip to main content

Locator

Struct Locator 

Source
pub struct Locator { /* private fields */ }
Expand description

A lazy, re-resolving handle to one or more AT-SPI elements.

See the module-level documentation for the resolution model.

Implementations§

Source§

impl Locator

Source

pub fn xpath(&self) -> &str

The XPath expression this locator resolves with.

Source

pub fn with_timeout(&self, timeout: Duration) -> Locator

Return a new locator with a per-call timeout override for auto-wait and wait_for_* methods. Duration::ZERO means “try once, don’t wait,” useful for negative assertions (“this element should NOT exist right now”).

Source

pub fn locate(&self, sub: &str) -> Locator

Scope a sub-expression to the nodes matched by this locator.

If sub is absolute (starts with /), it replaces the current selector entirely. Otherwise it’s evaluated as descendants of the current matches: (self)//sub.

Source

pub fn nth(&self, n: usize) -> Locator

Return a locator pinned to the n-th (0-indexed) match of this one.

Source

pub fn first(&self) -> Locator

Shorthand for nth(0).

Source

pub fn last(&self) -> Locator

Locator for the last match of this selector.

Source

pub fn parent(&self) -> Locator

Locator for the parent of the matched element(s).

Source

pub async fn count(&self) -> Result<usize>

Number of elements matched by this selector. Does not auto-wait — returns the current count, which may be zero.

Source

pub async fn all(&self) -> Result<Vec<Locator>>

Enumerate each match as a locator pinned by ordinal.

Each returned locator still re-resolves (so ordinal pins are evaluated on each use, not frozen to the AT-SPI identity observed at all() time).

Source

pub async fn inspect_all(&self) -> Result<Vec<ElementInfo>>

Take one AT-SPI snapshot and return full metadata for every match.

More efficient than calling all() and then metadata methods on each returned locator, which would re-snapshot per match.

Source

pub async fn name(&self) -> Result<Option<String>>

Accessible name of the matched element, or None when the element has no accessible name set.

Source

pub async fn role(&self) -> Result<String>

Raw AT-SPI role name (e.g. "push button", "menu item").

Falls back to the PascalCase XML element tag only when the snapshot lacks a role attribute — which shouldn’t happen for live snapshots, but can in hand-crafted test XML.

Source

pub async fn attribute(&self, key: &str) -> Result<Option<String>>

Read a single toolkit attribute by key.

Source

pub async fn attributes(&self) -> Result<HashMap<String, String>>

All toolkit attributes as a map.

Source

pub async fn is_showing(&self) -> Result<bool>

Whether the matched element currently has the Showing state.

Source

pub async fn is_enabled(&self) -> Result<bool>

Whether the matched element is currently interactable.

Returns true when the element has either the AT-SPI Enabled state or the Sensitive state — GTK reports the latter, Qt/others the former. Both mean “user can interact with this widget right now.”

Source

pub async fn text(&self) -> Result<String>

Text contents of the matched element via the AT-SPI Text interface. Unlike other metadata, text isn’t captured in the snapshot — each call makes a live read through the Text proxy after auto-waiting for the element to exist.

Source

pub async fn click(&self) -> Result<()>

Invoke the primary action (index 0) on the matched element.

Auto-waits for the element to be resolvable, showing, and enabled within the effective timeout. Requires exactly one match.

Source

pub async fn set_text(&self, text: &str) -> Result<()>

Replace the contents of an editable text element.

Auto-waits for the element to be resolvable, showing, and enabled.

Source

pub async fn focus(&self) -> Result<()>

Give keyboard focus to the matched element.

Auto-waits for the element to be resolvable, showing, and focusable — the last is a weaker check than “actionable” because some widgets accept focus without accepting activation (read-only text boxes, scroll regions, etc.). Uses AT-SPI’s Component::grab_focus under the hood.

§Toolkit caveats

This relies on the target widget implementing the AT-SPI Component interface. Some toolkits (notably GTK4 in its current form) don’t expose Component on all widgets — you may see Error::Atspi("NotSupported") from grab_focus even when the widget is visibly focusable on screen. When that happens the fallback is to drive focus via keyboard navigation (Tab / Shift+Tab) or synthesize a pointer click.

Source

pub async fn wait_for_visible(&self) -> Result<()>

Poll until the element exists and has the Showing state. Returns Ok(()) on success or the last encountered retriable error (or a Timeout error if the element existed but never became showing).

Source

pub async fn wait_for_hidden(&self) -> Result<()>

Poll until the element either doesn’t exist or doesn’t have the Showing state. The inverse of wait_for_visible.

Source

pub async fn wait_for_enabled(&self) -> Result<()>

Poll until the element exists and is interactable (has either the Enabled or Sensitive state — see Locator::is_enabled for why both are treated as equivalent).

Source

pub async fn wait_for_count(&self, n: usize) -> Result<()>

Poll until the selector matches exactly n elements. Useful for lists that populate asynchronously after a user action.

Source

pub async fn wait_for_text<F>(&self, pred: F) -> Result<String>
where F: Fn(&str) -> bool,

Poll until the element’s text contents satisfy pred. Returns the matching text on success so the caller can inspect it further.

Trait Implementations§

Source§

impl Clone for Locator

Source§

fn clone(&self) -> Locator

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more