Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Update readme and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepryde committed Oct 1, 2020
1 parent b5cbc09 commit 4c7578e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thirtyfour_query"
version = "0.3.0"
version = "0.3.1"
authors = ["Steve Pryde <steve@stevepryde.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ Advanced element query interface for the thirtyfour crate.

This crate is experimental and expected to have breaking changes often.

## Usage

With the new 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. This will never return an empty Vec. If either first() or all()
don't match anything, you'll get `WebDriverError::NoSuchElement` instead.
The error message will show the selectors used.

To set up default polling for all elements, do this:
```rust
// Disable implicit timeout in order to use new query interface.
driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;

let poller = ElementPoller::Time(Duration::new(20, 0), Duration::from_millis(500));
driver.config_mut().set("ElementPoller", poller)?;
```

Other ElementPoller options are also available, such as NoWait and NumTries.

## LICENSE

This work is dual-licensed under MIT or Apache 2.0.
Expand Down
36 changes: 36 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,43 @@
//!
//! See examples for more details.
//!
//! ## Experimental
//!
//! This crate is still experimental and expected to have breaking changes often, however
//! the basic interface is working.
//!
//! ## Usage
//!
//! With the new query interface you can do things like:
//!
//! ```no_run
//! 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:
//!
//! ```no_run
//! 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. This will never return an empty Vec. If either first() or all()
//! don't match anything, you'll get `WebDriverError::NoSuchElement` instead.
//! The error message will show the selectors used.
//!
//! To set up default polling for all elements, do this:
//! ```no_run
//! // Disable implicit timeout in order to use new query interface.
//! driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;
//!
//! let poller = ElementPoller::Time(Duration::new(20, 0), Duration::from_millis(500));
//! driver.config_mut().set("ElementPoller", poller)?;
//! ```
//!
//! Other ElementPoller options are also available, such as NoWait and NumTries.
pub mod query;

0 comments on commit 4c7578e

Please sign in to comment.