Skip to main content

Element

Struct Element 

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

A live element with lazy navigation via a provider reference.

Element dereferences to ElementData, so all properties (role, name, value, states, etc.) are accessible via field access. Navigation methods (parent(), children()) call the provider on demand.

Elements are cheap to clone (they share the provider via Arc).

Implementations§

Source§

impl Element

Source

pub fn new(data: ElementData, provider: Arc<dyn Provider>) -> Self

Create an Element from raw data and a provider reference.

Source

pub fn data(&self) -> &ElementData

Get the underlying ElementData.

Source

pub fn provider(&self) -> &Arc<dyn Provider> ⓘ

Get the provider reference.

Source

pub fn children(&self) -> Result<Vec<Element>>

Get direct children of this element.

Each call queries the provider — results are not cached.

Source

pub fn parent(&self) -> Result<Option<Element>>

Get the parent element, if any (root-level elements have no parent).

Each call queries the provider — results are not cached.

Source

pub fn pid(&self) -> Option<u32>

Get the process ID from the element data.

Source

pub fn tree(&self, max_depth: Option<usize>) -> Result<TreeNode>

Capture the subtree rooted at this element as a recursive snapshot.

max_depth limits traversal depth: 0 = only this node (no children), 1 = node + direct children, and so on. None traverses the full subtree.

Source

pub fn dump(&self, max_depth: Option<usize>) -> Result<String>

Render the subtree rooted at this element as an indented string.

Each line is {indent}{role} "{name}" [value="{value}"]. Returns the string without printing it. Same depth semantics as Element::tree.

Source

pub fn press(&self) -> Result<()>

Click / invoke this element via the accessibility action layer.

Source

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

Set keyboard focus to this element.

Source

pub fn blur(&self) -> Result<()>

Remove keyboard focus from this element.

Source

pub fn toggle(&self) -> Result<()>

Toggle a two- or three-state control (checkbox, switch).

Source

pub fn select(&self) -> Result<()>

Select this element (list item, tab, row).

Source

pub fn expand(&self) -> Result<()>

Expand a disclosure, menu, combo box, or tree item.

Source

pub fn collapse(&self) -> Result<()>

Collapse an expanded element.

Source

pub fn show_menu(&self) -> Result<()>

Open this element’s context menu or dropdown.

Source

pub fn increment(&self) -> Result<()>

Increment a numeric control (slider, spinner) by its platform step.

Source

pub fn decrement(&self) -> Result<()>

Decrement a numeric control (slider, spinner) by its platform step.

Source

pub fn scroll_into_view(&self) -> Result<()>

Scroll this element into the visible area.

No-op on macOS — the macOS accessibility API has no equivalent.

Source

pub fn set_value(&self, value: &str) -> Result<()>

Set the text value of this element. Replaces the entire value rather than inserting at the caret — use Element::type_text for insertion.

Source

pub fn set_numeric_value(&self, value: f64) -> Result<()>

Set the numeric value of this element (slider, spinner).

Returns Error::InvalidActionData if value is NaN or infinite.

Source

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

Insert text at the current cursor position.

Uses the platform accessibility API — never simulates keyboard events.

Source

pub fn select_text(&self, start: u32, end: u32) -> Result<()>

Select the text range from start to end (0-based character offsets).

Returns Error::InvalidActionData if start > end.

Source

pub fn perform_action(&self, action: &str) -> Result<()>

Perform an action by its snake_case name.

Use this for actions the element advertises in its actions list that don’t have a dedicated method. Well-known names ("press", "focus", etc.) also work — providers delegate to the named methods. The nullary window verbs are routed through the typed methods so the shared role guard applies on this path too: perform_action("activate") on a non-window element must fail exactly like activate() does, however the generic escape hatch is reached.

Source

pub fn activate(&self) -> Result<()>

Activate this window: bring it to the foreground and give it focus.

Source

pub fn minimize(&self) -> Result<()>

Minimize this window.

Source

pub fn maximize(&self) -> Result<()>

Maximize this window.

Distinct from Self::enter_fullscreen, which targets native fullscreen: maximize drives the platform’s maximized state, and a platform without an accessible maximize (macOS exposes no readable or writable zoom state) reports it as unsupported instead of substituting fullscreen.

Source

pub fn enter_fullscreen(&self) -> Result<()>

Put this window in native fullscreen.

Distinct from Self::maximize: fullscreen is the platform’s native fullscreen state (macOS AXFullScreen), and Self::restore leaves it. Callers should consult the element’s actions list before calling: the platforms that cannot enter fullscreen through an accessibility API (Windows/Linux) report it as unsupported.

Source

pub fn restore(&self) -> Result<()>

Restore this window to its normal state (from minimized/maximized/ fullscreen).

Source

pub fn close(&self) -> Result<()>

Close this window.

Source

pub fn move_to(&self, x: i32, y: i32) -> Result<()>

Move this window in the coordinates of ElementData::bounds (physical pixels on Windows, logical points elsewhere).

Source

pub fn resize_to(&self, width: u32, height: u32) -> Result<()>

Resize this window in the units of ElementData::bounds.

Returns Error::InvalidActionData if either dimension is 0.

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Self

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 Element

Source§

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

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

impl Deref for Element

Source§

type Target = ElementData

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ElementData

Dereferences the value.
Source§

impl Display for Element

Source§

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

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

impl<'a> From<&'a Element> for ClickTarget<'a>

Source§

fn from(el: &'a Element) -> Self

Converts to this type from the input type.
Source§

impl IntoPoint for &Element

Source§

impl Serialize for Element

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. 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, 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.