How can I resolve the PhantomJSDriver() from a different jar with same structure like selenium

28 views
Skip to first unread message

Debanjan Bhattacharjee

unread,
Jan 11, 2018, 1:39:58 AM1/11/18
to Selenium Users
Hello Everybody,

Till a few days back PhantomJSDriver was released bundled along with selenium-server-standalone-v.v.v.jar. So my Class was working fine as :

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

public class A_PhantomJS
{
    public static void main(String[] args) 
    {
          File path=new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
          System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
          WebDriver driver= new PhantomJSDriver();
          driver.manage().window().maximize();
          driver.get("https://www.google.co.in");
    }
}

Now selenium-server-standalone-v.v.v.jar doesn't bundles the jar for PhantomJSDriverdependency.

So I have downloaded the jar phantomjsdriver-1.1.0.jar and added as an external jar to my project.

You can see the structure of the phantomjsdriver-1.1.0.jar is similar to what it was earlier when it was bundled with selenium-server-standalone-v.v.v.jar



Now, though my Class gets resolved through :

import org.openqa.selenium.phantomjs.PhantomJSDriver;

But I am facing a Runtime exception of java.lang.NoClassDefFoundError exception caused by java.lang.ClassNotFoundException as follows :

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at demo.A_PhantomJS.main(A_PhantomJS.java:15)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

Line 15 being :

WebDriver driver= new PhantomJSDriver();

As per the error I have searched for org.openqa.selenium.browserlaunchers.Proxies within the phantomjsdriver-1.1.0.jar unable to find any clue.



Can anyone help me out please?

Thanks and Regards
DebanjanB

Debanjan Bhattacharjee

unread,
Jan 18, 2018, 10:21:20 AM1/18/18
to Selenium Users
Thanks Everyone.

The Question is solved now through Simon's comment : "There's a version of phantomjsdriver ('com.codeborne:phantomjsdriver:jar:1.4.4') that appears to be kept up to date with latest selenium releases. I'd suggest using that."



Thanks and Regards
Debanjan-B
Reply all
Reply to author
Forward
0 new messages