java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; while using PhantomJS 2.1.1 with Selenium

java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; while using PhantomJS 2.1.1 with Selenium



OS - Windows 7



PhantomJS version - 2.1.1



Selenium - 3.8.1(selenium-server).



JDK - 152.



I'm trying to run simple test, using PhantomJS:



1) initializing the driver:


System.setProperty("phantomjs.binary.path","src\main\resources\phantomjs.exe");
WebDriver driver = new PhantomJSDriver();



2) any test, let it be verifying text "welcome" on en.wikipedia.org:


driver.get("http://en.wikipedia.org");
System.out.println(driver.findElement(By.xpath("//div[contains(text(),'Welcome')]")).isDisplayed());



3) Running test, but receiving errors:


Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:232)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:94)



Googling showed, that such troubles occur time to time (non-compatible selenium/PhantomJS).
Question: is there any workaround for making last selenium(s) and 2.1.1 PhantomJS good friends?



note: any other driver works fine (edge, chrome, ff).





Can you update the Question with your Selenium/WebDriver/Browser versions along with your code trials?
– DebanjanB
Dec 11 '17 at 4:11





Question updated.
– Dmitry
Dec 11 '17 at 6:07




2 Answers
2



The error you are seeing says it all :


NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;


NoSuchMethodError



NoSuchMethodError extends IncompatibleClassChangeError and as per the Java Docs it is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler and this error can only occur at run time if the definition of a class has incompatibly changed.


NoSuchMethodError


IncompatibleClassChangeError



Perform the following steps :


JDK


Java 8 Update 151


Project Space


CCleaner


System Reboot



As you are using 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>



You need to update the line System.setProperty with the absolute path of the phantomjs binary as follows :


System.setProperty


phantomjs


File path=new File("C:\path\tophantomjs-2.1.1-windows\bin\phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.navigate().to("https://www.google.co.in/");



Execute your Test


Test





Works like a charm with 1.4.0, thanks man! Just note: not sure why, but on my machine I got troubles with updating from com.github.detro. From com.codeborne - no issues.
– Dmitry
Dec 11 '17 at 8:33



Just to add a different scenario where the same exception can be faced.



While using Eclipse below code was working :


File file = new File("C://phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();



While using Intellij, the same above code was throwing the error as mentioned in the question.



But the below worked with the Intellij :


DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\phantomjs.exe");

WebDriver driver = new PhantomJSDriver(capabilities);



Note:Dont forget to change the exe path.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj