1

I am running a Selenium WebDriver (ChromeDriver) in Java to do some basic automation, requiring user input. The user is able to, at any time, click the close (red X) button of the window. This doesn't call driver.quit() to properly quit the driver, leaving it running in the background and throwing a WebDriverException, which I don't want to happen. I am aware that there are no event listeners for browser window actions. I tried doing this:

WebDriver driver = null;
try {
    driver = new ChromeDriver();
    //do more stuff here
    WebDriverWait wait = new WebDriverWait(driver, 120);
    wait.until(
            //waiting conditions
    );
} catch (WebDriverException e) { //thrown after can't reach browser (browser closed)
    //handle exception
} finally {
    if (driver != null)
        driver.quit();
}
//continue with non-WebDriver parts of program

However, I need the program to move on quickly, and it often takes several seconds after the window is closed for the exception to be thrown. Also, this method just feels like bad programming anyway.

Is there a better way to quit ChromeDriver after it is manually closed?

D. Johnson
  • 21
  • 5

2 Answers2

0

U can call driver.quit in finally block

Amruta
  • 1,128
  • 1
  • 9
  • 19
  • Thank you for your suggestion. However, it doesn't solve the issue of taking too long to quit the driver and continue the problem. – D. Johnson Dec 10 '17 at 14:31
0

Browser .quit or browser.close functions.. Or kill the chrome processor using .kill function.. This solution might help you...

Amruta
  • 1,128
  • 1
  • 9
  • 19