[−][src]Crate thirtyfour_query
Thirtyfour_query provides an advanced query interface for thirtyfour
, featuring
powerful filtering and polling options.
See examples for more details.
Usage
ElementQuery
First, import the following:
use thirtyfour_query::{ElementPoller, ElementQueryable};
Next, set the default polling behaviour:
// Disable implicit timeout in order to use new query interface. driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?; let poller = ElementPoller::TimeoutWithInterval(Duration::new(10, 0), Duration::from_millis(500)); driver.config_mut().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:
// This won't wait. let elem_found = driver.query(By::Id("button1")).exists().await?; // This will wait, using the values from ElementPoller above. let elem = driver.query(By::Css("thiswont.match")).or(By::Id("button1")).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:
let elem = driver.query(By::Css("thiswont.match")).with_text("testing") .or(By::Id("button1")).with_class(StringMatch::new("pure-button").partial()).and_enabled() .first().await?;
Note the use of StringMatch
to provide a partial match on the class name.
See the documentation for StringMatch for more info.
To fetch all matching elements instead of just the first one, simply change first()
to all()
and you'll get a Vec instead. Also see all_required()
if you want it to return an error
when there are no matching elements.
All timeout, interval and ElementPoller details can be overridden on a per-call basis if
desired. See the ElementQuery
documentation for more details.
ElementWaiter
First, import the following:
use thirtyfour_query::{ElementPoller, ElementWaitable};
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(Duration::new(0, 0)).await?; let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::from_millis(500)); driver.config_mut().set("ElementPoller", poller)?;
Now you can do things like this:
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>
.
Structs
ElementQuery | High-level interface for performing powerful element queries using a builder pattern. |
ElementSelector | An ElementSelector contains a selector method (By) as well as zero or more filters. The filters will be applied to any elements matched by the selector. Selectors and filters all run in full on every poll iteration. |
ElementWaitCondition | |
ElementWaiter | |
StringMatch | This is a re-export of stringmatch::StringMatch. |
Enums
ElementPoller | Parameters used to determine the polling / timeout behaviour. |
ElementQuerySource | Elements can be queried from either a WebDriver or from a WebElement. The command issued to the webdriver will differ depending on the source, i.e. FindElement vs FindElementFromElement etc. but the ElementQuery interface is the same for both. |
Traits
ElementQueryable | Trait for enabling the ElementQuery interface. |
ElementWaitable | Trait for enabling the ElementWaiter interface. |