selenium异常:org.openqa.selenium.remote.UnreachableBrowserException
来源:互联网 发布:linux可执行文件结构 编辑:程序博客网 时间:2024/06/06 04:12
这几天在使用webdriver打开chrome浏览器的时候,程序在运行到driver.manage().window().maximize(); //将窗口最大化,就报错了:
org.openqa.selenium.remote.UnreachableBrowserException:Error communicatingwith the remotebrowser. It may have died.
这个错误在最初几天开始运行的时候并没有出现过,但是之后几乎总是会出现,查了很多资料才发现原因是socket连接达到了上限。重新看了遍程序,发现自己仅在程序正常运行到结束的时候,才调用了driver.quit()和serveice.stop(),但实际运行中程序大多以各种异常结束,这样的话,socket连接并没有关闭,会有大量的tcp连接处理establish和time_wait状态,导致无法继续请求新的连接,所以重新运行程序的时候,会报上述异常。
下面,首先记录下如何让程序跑起来,然后解释上述问题发生的原因,最后介绍下如何避免再次发生这种异常:
1、 如何让程序继续运行起来:
既然现在的问题是由于socket连接未被正常的释放,导致大量的tcp连接处于establish、time_wait、last_ack等状态造成的,那么直观的
解决方案就是:断开这些连接。最有效的解决方案就是,先查出这些tcp连接的进程号,然后直接杀死相应的进程。(windows系统)
首先以管理员身份运行cmd:
然后通过命:netstat –ano查看tcp连接的进程号,由于是本机和chromw浏览器建立的连接,所以这些连接的本地地址就是本机的IP,所以只需
查找协议为TCP,本地地址为主机IP,状态为established、close_wait、last_ack的进程PID:
最后通过命令:taskkill /F /PID429(以进程号429为例)强制杀死这些进程(之前以管理员身份运行也是为了避免出现执行taskkill后,出现
“无法访问”问题),但是在执行这条语句的时候请注意,你有可能会杀死圆口键盘的驱动,我就误杀了好几次,后来按键没反应,又通过U口键盘
开机后,执行
reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E96B-E325-11CE-BFC1-08002BE10318}/vUpperFilters /t reg_multi_sz /d
kbdclass /f后重启,才恢复正常的= =。
2、 如何避免问题再次发生
捕捉程序一切可能的异常结束,并在捕捉异常后,在finally{}语句中添加
{ driver.close(); service.stop(); }
避免连接未被释放
3、 问题是如何产生的
这个的解释挺详细的:http://www.cnblogs.com/olartan/p/4268269.html
- selenium异常:org.openqa.selenium.remote.UnreachableBrowserException
- webdriver selenium org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with
- selenium exceptionin java (org.openqa.selenium.remote.UnreachableBrowserException)
- webdriver selenium org.openqa.selenium.remote.UnreachableBrowserException: Error
- Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException
- org.openqa.selenium.StaleElementReferenceException
- org.openqa.selenium.StaleElementReferenceException
- org.openqa.selenium.ElementNotVisibleException
- Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException
- Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException
- org.openqa.selenium.NoSuchElementException: Unable to locate element: 异常解决方法
- org.openqa.selenium.ElementNotVisibleException: element not visible
- idea maven 程序包org.openqa.selenium不存在
- Appium报错:org.openqa.selenium.NoSuchSessionException
- Java Code Examples for org.openqa.selenium.JavascriptExecutor
- org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder错误
- java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver 问题解决方案
- TestSuite很多skipped,报错Exception org.openqa.selenium.SessionNotCreatedException
- 学习安排
- Linux内核中的软中断、tasklet和工作队列详解
- 大话设计模式(Python版)--装饰器模式
- poj3020 Antenna Placement(无向图最小边覆盖)
- 10-接口
- selenium异常:org.openqa.selenium.remote.UnreachableBrowserException
- Struts2 异常There is no Action mapped for namespace [/] and action name [auth] associated with context
- CSS 4.7 样式-轮廓
- go-tour-zh离线安装
- Jquery的全选和取消
- 选择排序
- Solr分布式索引SolrCloud原理总结
- Git笔记
- scp命令