stevepryde/thirtyfour

driver.quit().await? is not working

data987 opened this issue · 2 comments

I'm calling driver.quit() but it didn't close the browsers, if it doesn't find the element go straight to the Ok and it didn't close the browsers and I'm making a loop so at the end, there are three or four browsers open

let actual_value = driver.query(By::Css(&wait_element_string)).first().await?;
actual_value.wait_until().displayed().await?;
let wait_element_string = actual_value.inner_html().await?;
driver.quit().await?;

Ok(wait_element_string)

If the element isn't found, the query() call will return an error, and your ? operator will then exit the function, returning the error.

What you probably want is to put all of your logic in another function and then call quit() after that function returns, regardless of whether it returned Ok or Err.

Try something like this:

async fn get_element_string(driver: &WebDriver) -> WebDriverResult<String> {
    let actual_value = driver.query(By::Css(&wait_element_string)).first().await?;
    actual_value.wait_until().displayed().await?;
    let wait_element_string = actual_value.inner_html().await?;
    Ok(wait_element_string)
}

Then elsewhere you can do this:

let result = get_element_string(driver);
driver.quit().await?;
// Do something with result

This way driver.quit() will always be executed regardless of what happens in get_element_string().