pub struct Session { /* private fields */ }Expand description
A browser session. Used to control the browser.
When using thirtyfour (feature), this has a Deref impl to thirtyfour::WebDriver, so this
session can be seen as the driver.
Methods from Deref<Target = WebDriver>§
Sourcepub fn handle(&self) -> &Arc<SessionHandle> ⓘ
pub fn handle(&self) -> &Arc<SessionHandle> ⓘ
Returns a reference to the underlying SessionHandle. Useful for
extension code that needs to clone the handle (e.g. building a
WebElement from a JSON value via WebElement::from_json).
Most users won’t need this — methods on SessionHandle are already
reachable through Deref (e.g. driver.session_id()).
Sourcepub fn clone_with_config(&self, config: WebDriverConfig) -> WebDriver
pub fn clone_with_config(&self, config: WebDriverConfig) -> WebDriver
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 fn cdp(&self) -> Cdp
pub fn cdp(&self) -> Cdp
Get a Chrome DevTools Protocol handle for this session.
Cheap to call (just clones the underlying Arc<SessionHandle>).
Works on any Chromium-based driver session (chromedriver,
msedgedriver, Brave, Opera, etc.) — non-Chromium drivers will return
errors when CDP commands are issued.
§Example
let driver = WebDriver::new("http://localhost:4444", DesiredCapabilities::chrome()).await?;
let info = driver.cdp().browser().get_version().await?;
println!("user agent: {}", info.user_agent);For event subscription, upgrade to [crate::cdp::CdpSession] via
Cdp::connect (feature cdp-events).
Sourcepub fn driver_id(&self) -> Option<DriverId>
pub fn driver_id(&self) -> Option<DriverId>
Identifier of the driver process serving this session, if it was
launched via WebDriverManager. Returns None for sessions
constructed with WebDriver::new (i.e. talking to an externally-
managed driver server).
This identifier matches the DriverLogLine::driver_id field on log
events emitted via WebDriverManager::on_driver_log, so a closure
registered manager-wide can filter to “just this session’s driver”.
Sourcepub fn on_driver_log<F>(&self, f: F) -> Option<DriverLogSubscription>
pub fn on_driver_log<F>(&self, f: F) -> Option<DriverLogSubscription>
Subscribe to log lines from just this session’s driver process. Returns
None if this session wasn’t launched via WebDriverManager;
otherwise an RAII subscription whose drop unsubscribes.
Lines also continue flowing to any subscribers attached at the manager
level (via WebDriverManager::on_driver_log).