pub struct ElementQuery { /* private fields */ }
Expand description
Use ElementQuery to form a query into the tree of UI elements and then locate one or multiple matching elements.
ElementQuery uses the builder pattern to concatenate criteria, such as searching for descendants, or matching elements only with a certain id.
Construct an instance of this by calling ElementQuery::from_root
or ElementHandle::query_descendants
. Apply additional criterial on the returned ElementQuery
and fetch results by either calling Self::find_first()
to collect just the first match or
Self::find_all()
to collect all matches for the query.
Implementations§
Source§impl ElementQuery
impl ElementQuery
Sourcepub fn from_root(component: &impl ElementRoot) -> Self
pub fn from_root(component: &impl ElementRoot) -> Self
Creates a new element query starting at the root of the tree and matching all descendants.
Sourcepub fn match_descendants(self) -> Self
pub fn match_descendants(self) -> Self
Applies any subsequent matches to all descendants of the results of the query up to this point.
Sourcepub fn match_id(self, id: impl Into<String>) -> Self
pub fn match_id(self, id: impl Into<String>) -> Self
Include only elements in the results where ElementHandle::id()
is equal to the provided id
.
Sourcepub fn match_type_name(self, type_name: impl Into<String>) -> Self
pub fn match_type_name(self, type_name: impl Into<String>) -> Self
Include only elements in the results where ElementHandle::type_name()
is equal to the provided type_name
.
Sourcepub fn match_inherits(self, type_name: impl Into<String>) -> Self
pub fn match_inherits(self, type_name: impl Into<String>) -> Self
Include only elements in the results where ElementHandle::type_name()
or ElementHandle::bases()
is contains to the provided type_name
.
Sourcepub fn match_accessible_role(self, role: AccessibleRole) -> Self
pub fn match_accessible_role(self, role: AccessibleRole) -> Self
Include only elements in the results where ElementHandle::accessible_role()
is equal to the provided role
.
pub fn match_predicate( self, predicate: impl Fn(&ElementHandle) -> bool + 'static, ) -> Self
Sourcepub fn find_first(&self) -> Option<ElementHandle>
pub fn find_first(&self) -> Option<ElementHandle>
Runs the query and returns the first result; returns None if no element matches the selected criteria.
Sourcepub fn find_all(&self) -> Vec<ElementHandle>
pub fn find_all(&self) -> Vec<ElementHandle>
Runs the query and returns a vector of all matching elements.