selenium 无法访问浏览器异常,java 套接字异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12023305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
selenium unreachable browser exception, java socket exception
提问by Michael Roller
Recently, especially with multiple tasks and processes running on the same pc, selenium webdriver 2 is giving many unreachable browser exceptions which are always with a java socket exception:
最近,尤其是在同一台电脑上运行多个任务和进程时,selenium webdriver 2 给出了许多无法访问的浏览器异常,这些异常总是带有 java 套接字异常:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows Vista', os.arch: 'x86', os.version: '6.0', java.version: '1.7.0_05'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:493)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:182)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:185)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:174)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
Caused by: java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:150)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:575)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:319)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:297)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:136)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:357)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
... 7 more
Why does this happen so often? Is selenim 2.25 incompatible with firefox 14?
为什么这种情况经常发生?selenim 2.25 与 Firefox 14 不兼容吗?
回答by zvikachu
I found myself struggling with this issue for months, i really tried almost everything but still got random "UnreachableBrowserException" errors.
我发现自己在这个问题上挣扎了几个月,我真的尝试了几乎所有的方法,但仍然出现随机的“UnreachableBrowserException”错误。
This is the only working solution for me.
这对我来说是唯一可行的解决方案。
System.setProperty("java.net.preferIPv4Stack" , "true");
回答by kushan
I also had the same issue with Selenium Web Driver. Specially when I run a long test scripts without restarting the web driver. Then I moved to a new machine with much performance and then I could avoid it nearly 90 %.
Selenium Web Driver 也有同样的问题。特别是当我在不重新启动 Web 驱动程序的情况下运行很长的测试脚本时。然后我搬到了一台性能很高的新机器上,然后我可以避免它近 90%。
I assumed this happened because of lack of memory and I upgraded my RAM up to 4GB in my new machine.
我认为这是由于内存不足而发生的,我将新机器的 RAM 升级到 4GB。
That solved my issue and now everything is OK.
这解决了我的问题,现在一切正常。
Note : Please check whether you close the driver correctly after every test run.It also may lead to kill the driver due to memory leak.
注意:请在每次测试运行后检查您是否正确关闭了驱动程序。这也可能导致由于内存泄漏而杀死驱动程序。
回答by Ayyappadas
This is because of 2 reasons
这是因为 2 个原因
session not getting killed, try to kill the session and run the test again.
selenium web driver cannot find the FF browser to start it.
会话没有被杀死,尝试终止会话并再次运行测试。
selenium Web 驱动程序找不到 FF 浏览器来启动它。
Also Check all your client drivers and selenium-server.jar are placed on the libararies.
还要检查您的所有客户端驱动程序和 selenium-server.jar 是否放在库中。
Could you paste the configuration code on starting FF?
你能在启动FF时粘贴配置代码吗?
回答by Shivalika
I have faced the issue couple of times. There could be various reasons for the same.
我遇到过这个问题几次。可能有不同的原因。
Your browser instance is not closed properly. So checkout from your task manager whether it is killing the driver when you are calling driver.close() method. I have observed it for mostly chrome and IE. For Firefox it will automatically closes the instance.
FF and Webdriver version should be compatible to each other. Change your Webdriver jars and try it.
There may be unwanted jar present in your project. Xalan.jar is what gave me problem once. Remove it and see.
您的浏览器实例未正确关闭。因此,当您调用 driver.close() 方法时,请从您的任务管理器中检查它是否正在杀死驱动程序。我已经观察到它主要用于 chrome 和 IE。对于 Firefox,它将自动关闭实例。
FF 和 Webdriver 版本应该相互兼容。更改您的 Webdriver jar 并尝试一下。
您的项目中可能存在不需要的 jar。Xalan.jar 曾经给我带来了问题。取出来看看。