pub struct ElementQuery { /* private fields */ }
Expand description

High-level interface for performing powerful element queries using a builder pattern.

§Example:

// WebDriver::query() example.
let elem = driver.query(By::Css("div[data-section='section-buttons']")).first().await?;
// WebElement::query() example.
let elem_button = elem.query(By::Id("button1")).first().await?;

Implementations§

source§

impl ElementQuery

source

pub fn new( source: ElementQuerySource, by: By, poller: Arc<dyn IntoElementPoller + Send + Sync> ) -> Self

Create a new ElementQuery.

See WebDriver::query() or WebElement::query() rather than instantiating this directly.

source

pub fn options(self, options: ElementQueryOptions) -> Self

Provide the options to use with this query.

source

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

Provide a name that will be included in the error message if the query was not successful. This is useful for providing more context about this particular query.

source

pub fn ignore_errors(self, ignore: bool) -> Self

By default a query will ignore any errors that occur while polling for the desired element(s). However, this behaviour can be modified so that the waiter will return early if an error is returned from thirtyfour.

source

pub fn with_poller( self, poller: Arc<dyn IntoElementPoller + Send + Sync> ) -> Self

Use the specified ElementPoller for this ElementQuery. This will not affect the default ElementPoller used for other queries.

source

pub fn wait(self, timeout: Duration, interval: Duration) -> Self

Force this ElementQuery to wait for the specified timeout, polling once after each interval. This will override the poller for this ElementQuery only.

source

pub fn nowait(self) -> Self

Force this ElementQuery to not wait for the specified condition(s). This will override the poller for this ElementQuery only.

source

pub fn or(self, by: By) -> Self

Add a new selector to this ElementQuery. All conditions specified after this selector (up until the next or() method) will apply to this selector.

source

pub async fn exists(&self) -> WebDriverResult<bool>

Return true if an element matches any selector (including filters), otherwise false.

source

pub async fn not_exists(&self) -> WebDriverResult<bool>

Return true if no element matches any selector (including filters), otherwise false.

source

pub async fn first_opt(&self) -> WebDriverResult<Option<WebElement>>

Return the first WebElement that matches any selector (including filters).

Returns None if no elements match.

source

pub async fn first(&self) -> WebDriverResult<WebElement>

Return only the first WebElement that matches any selector (including filters).

Returns Err(WebDriverError::NoSuchElement) if no elements match.

source

pub async fn single(&self) -> WebDriverResult<WebElement>

Return only a single WebElement that matches any selector (including filters).

This method requires that only one element was found, and will return Err(WebDriverError::NoSuchElement) if the number of elements found after processing all selectors was not equal to 1.

This is useful because sometimes your element query is not specific enough and might accidentally match multiple elements. This is a common source of bugs in automated tests, because the first element might not actually be the one you expect.

By requiring that only one element is matched, you can be more sure that it is the one you intended.

source

pub async fn any(&self) -> WebDriverResult<Vec<WebElement>>

Return all WebElements that match any selector (including filters).

This will return when at least one element is found, after processing all selectors.

Returns an empty Vec if no elements match.

source

pub async fn any_required(&self) -> WebDriverResult<Vec<WebElement>>

Return all WebElements that match any selector (including filters).

This will return when at least one element is found, after processing all selectors.

Returns Err(WebDriverError::NoSuchElement) if no elements match.

source

pub async fn all(&self) -> WebDriverResult<Vec<WebElement>>

👎Deprecated since 0.32.0: use all_from_selector() instead

Return all WebElements that match any single selector (including filters).

source

pub async fn all_from_selector(&self) -> WebDriverResult<Vec<WebElement>>

Return all WebElements that match a single selector (including filters).

This will return when at least one element is found from any selector, without processing other selectors afterwards.

Returns an empty Vec if no elements match.

source

pub async fn all_required(&self) -> WebDriverResult<Vec<WebElement>>

👎Deprecated since 0.32.0: use all_from_selector_required() instead

Return all WebElements that match any single selector (including filters).

source

pub async fn all_from_selector_required( &self ) -> WebDriverResult<Vec<WebElement>>

Return all WebElements that match any single selector (including filters).

This will return when at least one element is found from any selector, without processing other selectors afterwards.

Returns Err(WebDriverError::NoSuchElement) if no elements match.

source

pub fn with_filter(self, f: ElementPredicate) -> Self

Add the specified ElementPredicate to the last selector.

source

pub fn and_enabled(self) -> Self

Only match elements that are enabled.

source

pub fn and_not_enabled(self) -> Self

Only match elements that are NOT enabled.

source

pub fn and_selected(self) -> Self

Only match elements that are selected.

source

pub fn and_not_selected(self) -> Self

Only match elements that are NOT selected.

source

pub fn and_displayed(self) -> Self

Only match elements that are displayed.

source

pub fn and_not_displayed(self) -> Self

Only match elements that are NOT displayed.

source

pub fn and_clickable(self) -> Self

Only match elements that are clickable.

source

pub fn and_not_clickable(self) -> Self

Only match elements that are NOT clickable.

source

pub fn with_text<N>(self, text: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified text. See the Needle documentation for more details on text matching rules.

source

pub fn without_text<N>(self, text: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified text. See the Needle documentation for more details on text matching rules.

source

pub fn with_id<N>(self, id: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified id. See the Needle documentation for more details on text matching rules.

source

pub fn without_id<N>(self, id: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified id. See the Needle documentation for more details on text matching rules.

source

pub fn with_class<N>(self, class_name: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that contain the specified class name. See the Needle documentation for more details on text matching rules.

source

pub fn without_class<N>(self, class_name: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not contain the specified class name. See the Needle documentation for more details on text matching rules.

source

pub fn with_tag<N>(self, tag_name: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified tag. See the Needle documentation for more details on text matching rules.

source

pub fn without_tag<N>(self, tag_name: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified tag. See the Needle documentation for more details on text matching rules.

source

pub fn with_value<N>(self, value: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn without_value<N>(self, value: N) -> Self
where N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn with_attribute<S, N>(self, attribute_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified attribute with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn without_attribute<S, N>(self, attribute_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified attribute with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn with_attributes<S, N>(self, desired_attributes: &[(S, N)]) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have all of the specified attributes with the specified values. See the Needle documentation for more details on text matching rules.

source

pub fn without_attributes<S, N>(self, desired_attributes: &[(S, N)]) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have any of the specified attributes with the specified values. See the Needle documentation for more details on text matching rules.

source

pub fn with_property<S, N>(self, property_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified property with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn without_property<S, N>(self, property_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified property with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn with_properties<S, N>(self, desired_properties: &[(S, N)]) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have all of the specified properties with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn without_properties<S, N>(self, desired_properties: &[(S, N)]) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have any of the specified properties with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn with_css_property<S, N>(self, css_property_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have the specified CSS property with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn without_css_property<S, N>(self, css_property_name: S, value: N) -> Self
where S: Into<String>, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have the specified CSS property with the specified value. See the Needle documentation for more details on text matching rules.

source

pub fn with_css_properties<S, N>( self, desired_css_properties: &[(S, N)] ) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that have all of the specified CSS properties with the specified values. See the Needle documentation for more details on text matching rules.

source

pub fn without_css_properties<S, N>( self, desired_css_properties: &[(S, N)] ) -> Self
where S: Into<String> + Clone, N: Needle + Clone + Send + Sync + 'static,

Only match elements that do not have any of the specified CSS properties with the specified values. See the Needle documentation for more details on text matching rules.

Trait Implementations§

source§

impl Debug for ElementQuery

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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