尝试在Linux服务器上的后端应用程序中创建PhantomJSDriver(版本1.9.8)时,我有一个奇怪的异常(java.util.concurrent.TimeoutException: null
)。同一应用程序在我的本地Mac上正常运行。
异常(exception):
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
最佳答案
您的实际问题更高:
Selenium无法找到或启动您的浏览器(这将解释为什么它可以在一台计算机上运行而不能在另一台计算机上运行)。浏览器是否安装在此Linux服务器上?用户Selenium是否以具有运行权限的身份运行?
关于java - 在Linux服务器上实例化PhantomJSDriver时发生TimeoutException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30748495/