Prevent automatically closing WebDriver at the end of navigation
Opened this issue · 1 comments
viktaur commented
Is there an elegant way of keeping the driver open to allow for manual interaction after the automation? This is what I currently have, which doesn't seem ideal:
#[tokio::main]
async fn main() -> WebDriverResult<()> {
// Initiate the chromedriver server.
match TcpListener::bind(("127.0.0.1", PORT)) {
// ...
};
sleep(Duration::from_secs(2)).await;
println!("Initiating WebDriver client");
let caps = DesiredCapabilities::chrome();
let driver = WebDriver::new(format!("http://localhost:{}", PORT), caps).await?;
driver.goto("https://wikipedia.org").await?;
// Automation happens here.
loop { }
// Manual user interaction happens here.
Ok(())
}
flippette commented
You can wrap it in a ManuallyDrop
, then call ManuallyDrop::into_inner
at some point:
let driver = ManuallyDrop::new(WebDriver::new(/* ... */));
// `ManuallyDrop` impls `Deref<Target = T>`, so you can call methods like normal
driver.goto("https://example.org").await?;
// it won't close until you either do this or call `WebDriver::quit`
let _ = ManuallyDrop::into_inner(driver);