PhantomjsDriver not working on both Windows and Linux

原文:http://stackoverflow.com/questions/20941518/phantomjsdriver-not-working-on-both-windows-and-linux


I have an application that uses Selenium Webdriver to get some information from a site. It works fine with FirefoxDriver and ChromeDriver, but when I tried to switch to PhantomJSDriver, I encountered some difficulties.

  1. On a Windows machine , it starts normally, then immediately begins spitting out the following lines over and over again:

Jan 05, 2014 7:28:43 PM org.apache.http.impl.client.DefaultRequestDirector tryEx ecute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond

This is repeated probably several hundred times for about 10 minutes until it finally loads the page; sometimes it doesn't even manage to load it at all.

  1. On a Linux machine, it tries to start, then returns the following:

Exception in thread "thread1" 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: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' 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:107) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:96) Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527) ... 7 more Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:16050/status] to be available after 20002 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163) ... 9 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) ... 10 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:258) at java.util.concurrent.FutureTask.get(FutureTask.java:119) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130) ... 11 more

What am I doing wrong? I've read a lot about how Phantomjs is so much faster than the other drivers, and would really like to use it, but if it takes 10 minutes to load each page, that's obviously not feasible.

I am running Selenium WebDriver version 2.38.0 and Phantomjs version 1.9.2.

Thank you very much in advance, bsg

EDIT Just to clarify, I don't think this has anything to do with my code; the errors on Linux are being thrown on the line where I try to start the PhantomJS driver, below.

   DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);                       
    caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        phantombinary//"/home/p/phantomjs-1.9.2-linux-x86_64/bin/phantomjs"
    );

    // Launch driver (will take care and ownership of the phantomjs process)
     WebDriver driver = new PhantomJSDriver(caps);
    System.out.println("starting driver");
share improve this question
 
 
@user1177636, thanks for the response. I don't think my code is the culprit, but I've posted it anyway. –  bsg  Jan 6 '14 at 1:56
 
Then I get an error saying that I need to specify the executable location. java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable –  bsg  Jan 6 '14 at 3:13
 
Sorry - would you mind telling me exactly how to do that? I see some code in the docs but it's a bit confusing.–  bsg  Jan 6 '14 at 3:21
 
let us continue this discussion in chat –  bsg  Jan 6 '14 at 4:05
 
Well, I got it working (with capabilities) on Windows. I had some other instances of FFDriver running and when I closed them, it started working without errors. I guess there were too many ports taken? Would still love to get it working on Linux. –  bsg  Jan 6 '14 at 22:02

2 Answers

If it is still not working for you on Linux, try below piece of code, it is working for me on Mac.

capabilities.setCapability("phantomjs.binary.path", "path of phantom binary/phantomjs")
share improve this answer
 

org.openqa.selenium.remote.UnreachableBrowserException clearly something to do with Phantom on Windows ensure Phantom is running(Set Environment variable and add PATH) Check that Remote Machine hub address is correct and you should be able to run phantomjs

Note: Selenium Server must be running on the desired remote machine.

DesiredCapabilities phantomBeast = DesiredCapabilities.phantomjs();

    try {
        webDriverInstance = new RemoteWebDriver(new URL(hubUrl), phantomBeast);
    } catch (Exception e) {
        //Do something 
    }
share improve this answer
 
 
Thanks for the response. I've never used Selenium Server - just regular webdriver. Why do I need to use it now? Does phantomjsdriver only use a remote server? How do I know what the hub address is - I'm not trying to run it on a remote machine. –  bsg  Jan 7 '14 at 19:25
 
Yes Start Selenium Server on your local machine from terminal or cmd (java -jar <seleniumserverjarfilename>)you will see the hub address on the command prompt, usually (127.0.0.1:4444/wd/hub) Parse the hub url, Run your test and you should be able to see output on the Terminal / Command Prompt –  Zach  Jan 8 '14 at 12:50 
 
I see this answer has had a lot of page views. I haven't accepted Zach's answer because I wasn't able to get it working for myself and don't really want to use Selenium Server, but it's quite possible that it's correct. –  bsg  Jul 20 '14 at 10:45
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值