与Selenium的PhatntomJs无法启动会话

时间:2016-07-27 16:13:57

标签: java selenium phantomjs headless-browser

我正在将PhantomJs与Selenium一起用于无头自动化。直到今天它对我来说都很有效。现在,我在初始化PhantomJs驱动程序时遇到以下异常。

我使用的代码如下:

Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities)caps).setCapability("phantomjs.binary.path", System.getProperty("user.dir")
                + "\\src\\main\\resources\\phantomjs.exe");

WebDriver driver = new PhantomJSDriver(caps);

ERROR:

 Jul 27, 2016 9:20:01 PM
org.openqa.selenium.phantomjs.PhantomJSDriverService  INFO:
executable: C:\Users\Ajatshatru
Singh\workspace\Assignment\src\main\resources\phantomjs.exe Jul 27,
2016 9:20:01 PM org.openqa.selenium.phantomjs.PhantomJSDriverService
 INFO: port: 48904 Jul 27, 2016 9:20:01 PM
org.openqa.selenium.phantomjs.PhantomJSDriverService  INFO:
arguments: [--webdriver=48904, --webdriver-logfile=C:\Users\Ajatshatru
Singh\workspace\Assignment\phantomjsdriver.log] Jul 27, 2016 9:20:01
PM org.openqa.selenium.phantomjs.PhantomJSDriverService  INFO:
environment: {} 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.39.0',
revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time:
'2013-12-16 13:18:38' System info: host: 'Ajatshatru', ip:
'10.31.32.236', os.name: 'Windows 8', os.arch: 'amd64', os.version:
'6.2', java.version: '1.7.0_51' Driver info: driver.version:
PhantomJSDriver   at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
  at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
  at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
  at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115)
  at
org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:110)
  at
org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:99)
  at Partik.Assignment.WebDriverQueue.main(WebDriverQueue.java:37)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting
for driver server to start. Build info: version: '2.39.0', revision:
'14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16
13:18:38' System info: host: 'Ajatshatru', ip: '10.31.32.236',
os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2',
java.version: '1.7.0_51' Driver info: driver.version: PhantomJSDriver
  at
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
  at
org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
  at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
  ... 6 more Caused by:
org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting
for [http://localhost:48904/status] to be available after 20004 ms    at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
  at
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
  ... 8 more Caused by:
com.google.common.util.concurrent.UncheckedTimeoutException:
java.util.concurrent.TimeoutException     at
com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
  at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
  ... 9 more Caused by: java.util.concurrent.TimeoutException     at
java.util.concurrent.FutureTask.get(Unknown Source)   at
com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
  ... 10 more 

1 个答案:

答案 0 :(得分:0)

我做了一个简单的重启。 :|