[英]How to fix [WARNING]: Timed out connecting to Chrome, retrying
I access Websites in a loop via selenium Java based.我通过基于 selenium Java 的循环访问网站。 Some of the sites crash imediately so that i get the error
一些网站立即崩溃,所以我得到了错误
[1618982990.911][WARNING]: Timed out connecting to Chrome, retrying...
after a short time.片刻之后。
So this is not a selenium issue i assume, since even chrome crashes if i visit the site manually because of js errors, saying unresonsive Website所以这不是我假设的 selenium 问题,因为如果我因为 js 错误而手动访问该网站,甚至 chrome 也会崩溃,说网站不合理
My problem is, that every time a site crashes, chromedriver and a chrome instance will stay alive so that i have high CPU usage after a short time.我的问题是,每次网站崩溃时,chromedriver 和 chrome 实例都会保持活动状态,这样我在短时间内就会有很高的 CPU 使用率。
Can i tell selenium to quit the instance if it is frozen?如果实例被冻结,我可以告诉 selenium 退出实例吗? But i dont know how this should be possible if it does not get answer from chrome anymore?
但我不知道如果它不再从 chrome 得到答案,这应该怎么可能?
Thankful for any solution or idea感谢任何解决方案或想法
Sometimes with some Windows version driver.quit() will not kill the chrome process which I have come across.有时使用一些 Windows 版本 driver.quit() 不会杀死我遇到的 chrome 进程。 So at the end of the script you can kill the chrome processes if exists using java code, if the driver.quit doesn't work.
因此,在脚本结束时,如果 driver.quit 不起作用,您可以使用 java 代码终止 chrome 进程。
Please refer stackoverflow link which has the code to kill the process if exists in Java and pass the chrome process to it.如果 Java 中存在终止进程的代码,请参考stackoverflow链接,并将 chrome 进程传递给它。
i found a workaround for anyone who would be interested.我为任何有兴趣的人找到了解决方法。 First setting up a pageLoadTimeout, after that force any chrome instance to be killed if an Exception is being thrown.
首先设置一个 pageLoadTimeout,然后在抛出异常时强制终止任何 chrome 实例。
try{
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
//some excecution code....
}
catch (Exception e) {
System.out.println("Error. Closing");
driver.quit();
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.