您所看到的错误说明了一切:
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
- 仅添加 Selenium-Java客户端v3.8.1 jar。
- 在使用 PhantomJSDriver(GhostDriver)时, 您需要添加以下 Maven依赖关系 :
<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



