PhantomjsDriver not working on both Windows and Linux

11,741

Solution 1

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")

Solution 2

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:
11,741

Related videos on Youtube

bsg
Author by

bsg

Updated on June 26, 2022

Comments

  • bsg
    bsg almost 2 years

    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");
    
  • bsg
    bsg over 10 years
    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.
  • Zach
    Zach over 10 years
    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
  • bsg
    bsg almost 10 years
    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.