pub struct Locator { /* private fields */ }Expand description
Composable element query with actions, property queries, and auto-waiting expectations.
Locators are lazy: they describe how to find an element but do not contact the server until an action, query, or expectation method is called.
All refinement methods return a new Locator (the type is Clone), so the
original remains usable.
Implementations§
Source§impl Locator
impl Locator
Sourcepub fn text(text: &str) -> Self
pub fn text(text: &str) -> Self
Locate elements whose visible text contains text (case-insensitive substring).
Sourcepub fn text_exact(text: &str) -> Self
pub fn text_exact(text: &str) -> Self
Locate elements whose visible text exactly equals text.
Sourcepub fn placeholder(text: &str) -> Self
pub fn placeholder(text: &str) -> Self
Locate elements by placeholder attribute.
Sourcepub fn and_text_exact(self, text: &str) -> Self
pub fn and_text_exact(self, text: &str) -> Self
Further filter by exact text match.
Sourcepub fn name(self, name: &str) -> Self
pub fn name(self, name: &str) -> Self
Further filter by accessible name (case-insensitive substring).
Sourcepub fn and_has_attribute(
self,
attr_name: &str,
attr_value: Option<&str>,
) -> Self
pub fn and_has_attribute( self, attr_name: &str, attr_value: Option<&str>, ) -> Self
Further filter by the presence (and optionally value) of an HTML attribute.
Sourcepub fn first(self) -> Self
pub fn first(self) -> Self
Select the first match (default behavior, explicit for readability).
Sourcepub async fn double_click(
&self,
client: &mut VictauriClient,
) -> Result<Value, TestError>
pub async fn double_click( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>
Double-click the resolved element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn fill(
&self,
client: &mut VictauriClient,
value: &str,
) -> Result<Value, TestError>
pub async fn fill( &self, client: &mut VictauriClient, value: &str, ) -> Result<Value, TestError>
Clear the field and fill it with value.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn type_text(
&self,
client: &mut VictauriClient,
text: &str,
) -> Result<Value, TestError>
pub async fn type_text( &self, client: &mut VictauriClient, text: &str, ) -> Result<Value, TestError>
Type text character-by-character into the resolved element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn press_key(
&self,
client: &mut VictauriClient,
key: &str,
) -> Result<Value, TestError>
pub async fn press_key( &self, client: &mut VictauriClient, key: &str, ) -> Result<Value, TestError>
Press a keyboard key (e.g. "Enter", "Control+c").
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn blur(
&self,
client: &mut VictauriClient,
) -> Result<Value, TestError>
pub async fn blur( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>
Remove focus from the currently active element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn scroll_into_view(
&self,
client: &mut VictauriClient,
) -> Result<Value, TestError>
pub async fn scroll_into_view( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>
Scroll the resolved element into view.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn select_option(
&self,
client: &mut VictauriClient,
values: &[&str],
) -> Result<Value, TestError>
pub async fn select_option( &self, client: &mut VictauriClient, values: &[&str], ) -> Result<Value, TestError>
Select option(s) in a <select> element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn check(
&self,
client: &mut VictauriClient,
) -> Result<Value, TestError>
pub async fn check( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>
Check a checkbox or radio button (sets checked = true).
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn uncheck(
&self,
client: &mut VictauriClient,
) -> Result<Value, TestError>
pub async fn uncheck( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>
Uncheck a checkbox (sets checked = false).
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn text_content(
&self,
client: &mut VictauriClient,
) -> Result<String, TestError>
pub async fn text_content( &self, client: &mut VictauriClient, ) -> Result<String, TestError>
Get the textContent of the resolved element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn inner_text(
&self,
client: &mut VictauriClient,
) -> Result<String, TestError>
pub async fn inner_text( &self, client: &mut VictauriClient, ) -> Result<String, TestError>
Get the innerText of the resolved element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn input_value(
&self,
client: &mut VictauriClient,
) -> Result<String, TestError>
pub async fn input_value( &self, client: &mut VictauriClient, ) -> Result<String, TestError>
Get the current value of an input/textarea/select element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn is_visible(
&self,
client: &mut VictauriClient,
) -> Result<bool, TestError>
pub async fn is_visible( &self, client: &mut VictauriClient, ) -> Result<bool, TestError>
Whether the resolved element is visible.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn is_enabled(
&self,
client: &mut VictauriClient,
) -> Result<bool, TestError>
pub async fn is_enabled( &self, client: &mut VictauriClient, ) -> Result<bool, TestError>
Whether the resolved element is enabled (not disabled).
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn is_checked(
&self,
client: &mut VictauriClient,
) -> Result<bool, TestError>
pub async fn is_checked( &self, client: &mut VictauriClient, ) -> Result<bool, TestError>
Whether the resolved element is checked (checkbox/radio).
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn is_focused(
&self,
client: &mut VictauriClient,
) -> Result<bool, TestError>
pub async fn is_focused( &self, client: &mut VictauriClient, ) -> Result<bool, TestError>
Whether the resolved element currently has focus.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn count(
&self,
client: &mut VictauriClient,
) -> Result<usize, TestError>
pub async fn count( &self, client: &mut VictauriClient, ) -> Result<usize, TestError>
Count the number of elements matching this locator.
§Errors
Returns errors from VictauriClient::call_tool.
Sourcepub async fn bounding_box(
&self,
client: &mut VictauriClient,
) -> Result<Option<Bounds>, TestError>
pub async fn bounding_box( &self, client: &mut VictauriClient, ) -> Result<Option<Bounds>, TestError>
Get the bounding rectangle of the resolved element, if available.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn get_attribute(
&self,
client: &mut VictauriClient,
attr_name: &str,
) -> Result<Option<String>, TestError>
pub async fn get_attribute( &self, client: &mut VictauriClient, attr_name: &str, ) -> Result<Option<String>, TestError>
Read the value of an HTML attribute on the resolved element.
§Errors
Returns TestError::ElementNotFound if no element matches.
Sourcepub async fn all(
&self,
client: &mut VictauriClient,
) -> Result<Vec<LocatorMatch>, TestError>
pub async fn all( &self, client: &mut VictauriClient, ) -> Result<Vec<LocatorMatch>, TestError>
Resolve all matching elements (ignoring the pick setting).
§Errors
Returns errors from VictauriClient::call_tool.
Sourcepub async fn all_text_contents(
&self,
client: &mut VictauriClient,
) -> Result<Vec<String>, TestError>
pub async fn all_text_contents( &self, client: &mut VictauriClient, ) -> Result<Vec<String>, TestError>
Sourcepub fn expect<'a>(&'a self, client: &'a mut VictauriClient) -> LocatorExpect<'a>
pub fn expect<'a>(&'a self, client: &'a mut VictauriClient) -> LocatorExpect<'a>
Create an auto-waiting expectation builder for this locator.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Locator
impl RefUnwindSafe for Locator
impl Send for Locator
impl Sync for Locator
impl Unpin for Locator
impl UnsafeUnpin for Locator
impl UnwindSafe for Locator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.