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

后端 未结 2 2004
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 05:01

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:

相关标签:
2条回答
  • 2020-12-12 05:31

    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.

    0 讨论(0)
  • 2020-12-12 05:41

    The error you are seeing says it all :

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

    Class 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.

    Solution

    Perform the following steps :

    • Update your JDK to the most recent versions (Java 8 Update 151)
    • Clean up the Project Space from the IDE.
    • Run CCleaner tool to wipe off all the OS system chores.
    • Take a System Reboot
    • Add only Selenium-Java Clients v3.8.1 jar.
    • 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 :

      File path=new File("C:\\path\\\to\phantomjs-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

    0 讨论(0)
提交回复
热议问题