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
impl Element
Sourcepub fn new(data: ElementData, provider: Arc<dyn Provider>) -> Self
pub fn new(data: ElementData, provider: Arc<dyn Provider>) -> Self
Create an Element from raw data and a provider reference.
Sourcepub fn data(&self) -> &ElementData
pub fn data(&self) -> &ElementData
Get the underlying ElementData.
Sourcepub fn children(&self) -> Result<Vec<Element>>
pub fn children(&self) -> Result<Vec<Element>>
Get direct children of this element.
Each call queries the provider — results are not cached.
Sourcepub fn parent(&self) -> Result<Option<Element>>
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.
Sourcepub fn tree(&self, max_depth: Option<usize>) -> Result<TreeNode>
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.
Sourcepub fn dump(&self, max_depth: Option<usize>) -> Result<String>
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.
Sourcepub fn press(&self) -> Result<()>
pub fn press(&self) -> Result<()>
Click / invoke this element via the accessibility action layer.
Open this element’s context menu or dropdown.
Sourcepub fn increment(&self) -> Result<()>
pub fn increment(&self) -> Result<()>
Increment a numeric control (slider, spinner) by its platform step.
Sourcepub fn decrement(&self) -> Result<()>
pub fn decrement(&self) -> Result<()>
Decrement a numeric control (slider, spinner) by its platform step.
Sourcepub fn scroll_into_view(&self) -> Result<()>
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.
Sourcepub fn set_value(&self, value: &str) -> Result<()>
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.
Sourcepub fn set_numeric_value(&self, value: f64) -> Result<()>
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.
Sourcepub fn type_text(&self, text: &str) -> Result<()>
pub fn type_text(&self, text: &str) -> Result<()>
Insert text at the current cursor position.
Uses the platform accessibility API — never simulates keyboard events.
Sourcepub fn select_text(&self, start: u32, end: u32) -> Result<()>
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.
Sourcepub fn perform_action(&self, action: &str) -> Result<()>
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.
Sourcepub fn activate(&self) -> Result<()>
pub fn activate(&self) -> Result<()>
Activate this window: bring it to the foreground and give it focus.
Sourcepub fn maximize(&self) -> Result<()>
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.
Sourcepub fn enter_fullscreen(&self) -> Result<()>
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.
Sourcepub fn restore(&self) -> Result<()>
pub fn restore(&self) -> Result<()>
Restore this window to its normal state (from minimized/maximized/ fullscreen).
Sourcepub fn move_to(&self, x: i32, y: i32) -> Result<()>
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).
Sourcepub fn resize_to(&self, width: u32, height: u32) -> Result<()>
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.