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 freeze 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 async fn new_with_config_and_client<S, C>(
server_url: S,
capabilities: C,
config: WebDriverConfig,
client: impl HttpClient,
) -> WebDriverResult<Self>
pub async fn new_with_config_and_client<S, C>( server_url: S, capabilities: C, config: WebDriverConfig, client: impl HttpClient, ) -> 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: Although WebDriver does close when all instances go out of scope.
When this happens it blocks the current executor,
therefore, if you know when a webdriver is no longer used/required
call this method and await it to more or less “asynchronously drop” it
this also allows you to catch errors during quitting,
and possibly panic or report back to the user
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WebDriver
impl !RefUnwindSafe for WebDriver
impl Send for WebDriver
impl Sync for WebDriver
impl Unpin for WebDriver
impl !UnwindSafe for WebDriver
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)