Skip to main content

Locator

Struct Locator 

Source
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

Source

pub fn role(role: &str) -> Self

Locate elements by ARIA role (e.g. "button", "textbox").

Source

pub fn text(text: &str) -> Self

Locate elements whose visible text contains text (case-insensitive substring).

Source

pub fn text_exact(text: &str) -> Self

Locate elements whose visible text exactly equals text.

Source

pub fn test_id(id: &str) -> Self

Locate elements by data-testid attribute.

Source

pub fn css(selector: &str) -> Self

Locate elements by CSS selector.

Source

pub fn label(text: &str) -> Self

Locate form controls by their associated <label> text.

Source

pub fn placeholder(text: &str) -> Self

Locate elements by placeholder attribute.

Source

pub fn alt_text(alt: &str) -> Self

Locate elements by alt attribute (images, areas).

Source

pub fn title(title: &str) -> Self

Locate elements by title attribute.

Source

pub fn and_text(self, text: &str) -> Self

Further filter by case-insensitive text substring.

Source

pub fn and_text_exact(self, text: &str) -> Self

Further filter by exact text match.

Source

pub fn and_role(self, role: &str) -> Self

Further filter by ARIA role.

Source

pub fn name(self, name: &str) -> Self

Further filter by accessible name (case-insensitive substring).

Source

pub fn and_tag(self, tag: &str) -> Self

Further filter by HTML tag name.

Source

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.

Source

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

Select the nth match (zero-based).

Source

pub fn first(self) -> Self

Select the first match (default behavior, explicit for readability).

Source

pub fn last(self) -> Self

Select the last match.

Source

pub async fn click( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>

Click the resolved element.

§Errors

Returns TestError::ElementNotFound if no element matches.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn hover( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>

Hover over the resolved element.

§Errors

Returns TestError::ElementNotFound if no element matches.

Source

pub async fn focus( &self, client: &mut VictauriClient, ) -> Result<Value, TestError>

Focus the resolved element.

§Errors

Returns TestError::ElementNotFound if no element matches.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn all_text_contents( &self, client: &mut VictauriClient, ) -> Result<Vec<String>, TestError>

Get textContent for every matching element.

§Errors

Returns errors from VictauriClient::call_tool.

Source

pub fn expect<'a>(&'a self, client: &'a mut VictauriClient) -> LocatorExpect<'a>

Create an auto-waiting expectation builder for this locator.

Trait Implementations§

Source§

impl Clone for Locator

Source§

fn clone(&self) -> Locator

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 Locator

Source§

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

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

impl Display for Locator

Source§

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

Formats the value using the given formatter. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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> 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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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