Advanced element query/polling interfaces for the thirtyfour crate.
These interfaces are currently experimental and will likely be merged into
the main thirtyfour
crate once they are stable.
If you can help by testing these and providing feedback that would be appreciated.
Usage
ElementQuery
First, import the following:
use ;
Next, set the default polling behaviour:
// Disable implicit timeout in order to use new query interface.
driver.set_implicit_wait_timeout.await?;
let poller = TimeoutWithInterval;
driver.config_mut.set?;
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:
let elem_text =
driver.query.or.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:
driver.query.with_text
.or.with_class.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>
.
ElementWaiter
First, import the following:
use ;
Next, set the default polling behaviour (same as for ElementQuery - the same polling settings are used for both):
// Disable implicit timeout in order to use new query interface.
driver.set_implicit_wait_timeout.await?;
let poller = TimeoutWithInterval;
driver.config_mut.set?;
Now you can do things like this:
elem.wait.until.displayed.await?;
elem.wait.until_not.displayed.await?;
elem.wait.until.enabled.await?;
elem.wait.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>
.
LICENSE
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