Reputation: 4172
I tired to implement Phantomjs driver to Selenium tests but it throws me this error. java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; The Phantom library is https://mvnrepository.com/artifact/org.jboss.arquillian.extension/arquillian-phantom-driver version 1.2.1.1 and Java version is 1.8 Implementation looks like:
if( driver == null )
{
if( which == CHROME )
{
System.setProperty("webdriver.chrome.driver", which);
driver = new ChromeDriver();
}
else if ( which == PHANTOM )
{
System.setProperty("webdriver.phantomjs.driver", which);
driver = new PhantomJSDriver();
}
}
What should I do to force it to work? Is it right Phantom library? Thanks.
Upvotes: 1
Views: 560
Reputation: 186
This approach works for me:
download a driver: https://phantomjs.org/download.html
add this dependecy:
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
<scope>compile</scope>
</dependency>
add to your code:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("phantomjs.binary.path", "pathToBin");
driver = new PhantomJSDriver(capabilities);
NOTE: I'm using Selenium version 3.8.1
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.8.1</version>
</dependency>
Upvotes: 1
Reputation: 2881
For PhantomJSDriver (GhostDriver) you need to add the following Maven Dependency :
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.0</version>
</dependency>
Additionally, update the line System.setProperty
with the absolute path of the phantomjs
binary as follows :
File path=new File("C:\\path\\\to\phantomjs-x.x.x-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.navigate().to("https://www.google.co.in/");
Note: You can clean your project in IDE and use Selenium-Java Clients
dependency only.
Upvotes: 1