简体   繁体   中英

Selenium Java: Guarantee chromedriver.exe shutdown when program exits

I'm using Selenium in Java to automate Google Chrome . When my program exits, a chromedriver.exe instance is left in memory. I know that I can use driver.quit() in eg a finally block to shut down the current instance. However, if the Java application is killed at any time (like during debug sessions), this cleanup is of course never performed.

I'm looking for a solution to make the chromedriver.exe a child process of the Java process so when the Java process exits, the child process also dies automatically. Solutions like Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe"); kill all chromedriver.exe instances but this may mess up other Selenium processes on the system which is not ideal. Also this would not work against forcibly killing the process either.

you can use "Selenium Grid" - it has a cleanup cycle of all idle sessions every XXX amount of time (default is 5 minutes) - https://www.seleniumhq.org/docs/07_selenium_grid.jsp

This way, your selenium server will take care of calling driver.quit() [which is the preferred way for killing your processes - release Selenium chromedriver.exe from memory even if your Java program is killed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM