Advanced element query/polling interfaces for the thirtyfour crate.
First, import the following:
rust
use thirtyfour_query::{ElementPoller, ElementQueryable};
Next, set the default polling behaviour: ```rust // Disable implicit timeout in order to use new query interface. driver.setimplicitwait_timeout(Duration::new(0, 0)).await?;
let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::frommillis(500)); driver.configmut().set("ElementPoller", poller)?; ```
Other ElementPoller options are also available, such as NoWait and NumTriesWithInterval. These can be overridden on a per-query basis as needed.
Now, using the query interface you can do things like:
rust
let elem_text =
driver.query(By::Css("thiswont.match")).or(By::Id("searchInput")).first().await?;
This will execute both queries once per poll iteration and return the first one that matches. You can also filter on one or both match arms like this:
rust
driver.query(By::Css("thiswont.match")).with_text("testing")
.or(By::Id("searchInput")).with_class("search").and_not_enabled()
.first().await?;
To fetch all matching elements instead of just the first one, simply change first() to all() and you'll get a Vec instead.
ElementQuery also allows the user of custom predicates that take a &WebElement
argument
and return a WebDriverResult<bool>
.
First, import the following:
rust
use thirtyfour_query::{ElementPoller, ElementWaitable};
Next, set the default polling behaviour (same as for ElementQuery - the same polling settings are used for both): ```rust // Disable implicit timeout in order to use new query interface. driver.setimplicitwait_timeout(Duration::new(0, 0)).await?;
let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::frommillis(500)); driver.configmut().set("ElementPoller", poller)?; ```
Now you can do things like this: ```rust elem.wait("Timed out waiting for element to be displayed").until().displayed().await?; elem.wait("Timed out waiting for element to disappear").until_not().displayed().await?;
elem.wait("Timed out waiting for element to become enabled").until().enabled().await?; elem.wait("Timed out waiting for element to become disabled").until_not().enabled().await?; ```
And so on, including selected()
and stale()
.
ElementWaiter also allows the user of custom predicates that take a &WebElement
argument
and return a WebDriverResult<bool>
.
This work is dual-licensed under MIT or Apache 2.0. You can choose either license if you use this work.
SPDX-License-Identifier: MIT OR Apache-2.0