简体   繁体   English

Selenium Java:当程序退出时保证chromedriver.exe关闭

[英]Selenium Java: Guarantee chromedriver.exe shutdown when program exits

I'm using Selenium in Java to automate Google Chrome . 我在Java中使用Selenium来自动化Google Chrome When my program exits, a chromedriver.exe instance is left in memory. 当我的程序退出时, chromedriver.exe实例将保留在内存中。 I know that I can use driver.quit() in eg a finally block to shut down the current instance. 我知道我可以在例如finally块中使用driver.quit()来关闭当前实例。 However, if the Java application is killed at any time (like during debug sessions), this cleanup is of course never performed. 但是,如果Java应用程序在任何时候被杀死(例如在调试会话期间),则当然不会执行此清理。

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. 我正在寻找一种解决方案,使chromedriver.exe成为Java进程的子进程,因此当Java进程退出时,子进程也会自动死亡。 Solutions like Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe"); 解决方案如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. 杀死所有chromedriver.exe实例但这可能会chromedriver.exe系统上其他不理想的Selenium进程。 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 你可以使用“Selenium Grid” - 它每隔XXX个时间(默认为5分钟)有一个所有空闲会话的清理周期 - 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. 这样,你的selenium服务器将负责调用driver.quit()[这是杀死你的进程的首选方法 - 即使你的Java程序被杀死, 也会从内存中释放Selenium chromedriver.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 硒chromedriver.exe - Selenium chromedriver.exe 硒找不到chromedriver.exe - selenium is not locating chromedriver.exe Java Selenium Chromedriver.exe 不存在 IllegalStateException - Java Selenium Chromedriver.exe Does not Exist IllegalStateException 我可以使用getResource打开chromedriver.exe(FireFox / IE)吗? *硒Java - Can I open the chromedriver.exe (FireFox / IE) using getResource? *Selenium-Java chromedriver.exe和selenium-chrome-driver.jar之间的区别 - difference between chromedriver.exe and selenium-chrome-driver.jar Selenium WebDriver 3.0.1 chromedriver.exe 2.25 --whitelisted-ips="" - Selenium WebDriver 3.0.1 chromedriver.exe 2.25 --whitelisted-ips=“” 程序退出时关闭执行程序服务 - shutdown executor service when program exits 无法在 Selenium 网格中运行测试 Maven 设置中引用 Chromedriver.exe - Unable to run tests in Selenium Grid referencing Chromedriver.exe in Maven setup 如何在没有 ChromeDriver.exe 的情况下从 Selenium 远程 Web 驱动程序启动 GoogleChrome - How to Launch GoogleChrome from Selenium Remote Web Driver without ChromeDriver.exe 如何在 selenium 中不设置本地驱动程序的情况下启动浏览器? (不访问本地chromeDriver.exe) - How to launch browser without setting local driver in selenium? (Without accessing local chromeDriver.exe)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM