To interact with a browser, you must first create a Client using a ClientBuilder. You can choose between different TLS providers depending on your feature flags:
- Use
ClientBuilder::native() if the native-tls feature is enabled (default). - Use
ClientBuilder::rustls() if the rustls-tls feature is enabled. - Use
ClientBuilder::new(connector) to provide a custom HTTP connector.
After configuring the builder, call .connect(webdriver_url) to establish the session.
Note for geckodriver users: geckodriver does not support multiple simultaneous instances. Ensure you explicitly call client.close().await to end the session, even if an error occurs.
use fantoccini::{ClientBuilder, Locator};
#[tokio::main]
async fn main() -> Result<(), fantoccini::error::CmdError> {
// Connecting using "native" TLS (with feature `native-tls`; on by default)
let c = ClientBuilder::native()
.connect("http://localhost:4444")
.await
.expect("failed to connect to WebDriver");
// ... use the client ...
c.close().await
}