Struct thirtyfour::WebDriver
source · pub struct WebDriver {
pub handle: Arc<SessionHandle>,
}
Expand description
The WebDriver
struct encapsulates an async Selenium WebDriver browser
session.
§Example:
use thirtyfour::prelude::*;
let caps = DesiredCapabilities::firefox();
// NOTE: this assumes you have a WebDriver compatible server running
// at http://localhost:4444
// e.g. `geckodriver -p 4444`
// NOTE: If using selenium 3.x, use "http://localhost:4444/wd/hub/session" for the url.
let driver = WebDriver::new("http://localhost:4444", caps).await?;
driver.goto("https://www.rust-lang.org/").await?;
// Always remember to close the session.
driver.quit().await?;
Fields§
§handle: Arc<SessionHandle>
The underlying session handle.
Implementations§
source§impl WebDriver
impl WebDriver
sourcepub async fn new<S, C>(server_url: S, capabilities: C) -> WebDriverResult<Self>
pub async fn new<S, C>(server_url: S, capabilities: C) -> WebDriverResult<Self>
Create a new WebDriver as follows:
§Example
let caps = DesiredCapabilities::firefox();
// NOTE: this assumes you have a WebDriver compatible server running
// at http://localhost:4444
// e.g. `geckodriver -p 4444`
// NOTE: If using selenium 3.x, use "http://localhost:4444/wd/hub/session" for the url.
let driver = WebDriver::new("http://localhost:4444", caps).await?;
§Using Selenium Server
- For selenium 3.x, you need to also add “/wd/hub/session” to the end of the url (e.g. “http://localhost:4444/wd/hub/session”)
- For selenium 4.x and later, no path should be needed on the url.
§Troubleshooting
- If the webdriver appears to hang or give no response, please check that the capabilities object is of the correct type for that webdriver.
sourcepub async fn new_with_config<S, C>(
server_url: S,
capabilities: C,
config: WebDriverConfig
) -> WebDriverResult<Self>
pub async fn new_with_config<S, C>( server_url: S, capabilities: C, config: WebDriverConfig ) -> WebDriverResult<Self>
Create a new WebDriver
with the specified WebDriverConfig
.
Use WebDriverConfig::builder().build()
to construct the config.
sourcepub fn clone_with_config(&self, config: WebDriverConfig) -> Self
pub fn clone_with_config(&self, config: WebDriverConfig) -> Self
Clone this WebDriver
keeping the session handle, but supplying a new WebDriverConfig
.
This still uses the same underlying client, and still controls the same browser
session, but uses a different WebDriverConfig
for this instance.
This is useful in cases where you want to specify a custom poller configuration (or
some other configuration option) for only one instance of WebDriver
.
sourcepub async fn quit(self) -> WebDriverResult<()>
pub async fn quit(self) -> WebDriverResult<()>
End the webdriver session and close the browser.
NOTE: The browser will not close automatically when WebDriver
goes out of scope.
Thus if you intend for the browser to close once you are done with it, then
you must call this method at that point, and await it.