
您所看到的错误说明了一切:
NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
NoSuchMethodError
NoSuchMethodError
扩展,IncompatibleClassChangeError
并且根据 Java Docs
,如果应用程序尝试调用类的指定方法(静态或实例),并且该类不再具有该方法的定义,则抛出该异常。通常,此错误由编译器捕获,并且只有在类的定义发生不兼容的更改时,此错误才会在运行时发生。
执行以下步骤:
JDK到最新版本(
Java 8 Update 151)
Project Space从IDE中清理。
CCleaner工具以清除所有OS系统杂务。
System Reboot
<dependency> <groupId>com.github.detro</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.4.0</version> </dependency>
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/");Test