Search code examples
javaseleniumchromiumselenium-chromedriverterminate

Close program when browser closes


I'm creating a Chrome driver like so:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(CHROME);
chromeOptions.addArguments("user-data-dir=" + USER_DATA_DIR);

ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);

If i close the browser (by clicking the red X) my java program just keeps alive. I then have to click the terminate button in Eclipse. How can i exit it automaticly when the browser closes?


Solution

  • Selenium can't recognize manual operations on the browser. To terminate the program automatically close the browser using driver.close();