我正在尝试使用Selenium Java实例化PhantomJS驱动程序。以下是代码:
File file = new File("C:\\Softwares\\drivers\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
我尝试过使用不同版本的Selenium,我得到了同样的例外:
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.HttpVerb
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/HttpVerb
at org.openqa.selenium.phantomjs.PhantomJSDriver.getCustomCommands(PhantomJSDriver.java:166)
at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.<init>(PhantomJSCommandExecutor.java:62)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:110)
我在项目中使用以下依赖项列表:
我使用过时版本的selenium库的原因是由于我在互联网上发现的一篇文章说远程/ HttpVerb已弃用并且降级库会删除错误。但是,我仍然收到此错误
答案 0 :(得分:1)
请在POM中检查此依赖性
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.53.1</version>
</dependency>
检查此课程是否存在