在Linux服务器上实例化PhantomJSDriver时出现TimeoutException

时间:2015-06-10 06:17:19

标签: java linux selenium phantomjs

尝试在Linux服务器上的后端应用程序中创建PhantomJSDriver(版本1.9.8)时,我有奇怪的异常(java.util.concurrent.TimeoutException: null)。相同的应用程序在我的本地Mac上没有问题。

例外:

ERROR 12721 --- [http-nio-9095-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] :
Servlet.service() for servlet [dispatcherServlet] in context with
path [] threw exception [Request processing failed; nested 
exception is 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: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: 
'3.12.9-2-ARCH', java.version: '1.8.0_25'
Driver info: driver.version: PhantomJSDriver] 
with root cause 

java.util.concurrent.TimeoutException: null 
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:107)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:96)

导致此问题的源代码:

DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
String [] phantomJsArgs = {"--ignore-ssl-errors=yes", "--ssl-protocol=any"};
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
PhantomJSDriver driver = new PhantomJSDriver(capabilities); // <--- here exception is thrown

1 个答案:

答案 0 :(得分:0)

您的实际问题更高了:

  

请求处理失败;嵌套异常是org.openqa.selenium.remote.UnreachableBrowserException:   无法开始新会话。可能的原因是远程服务器的无效地址或浏览器启动失败。

Selenium无法找到或启动您的浏览器(这可以解释为什么它可以在一台机器上运行而不是另一台机器上运行)。浏览器是否安装在此Linux服务器上?用户Selenium是否有权运行它?