2017-09-19 43 views
0

我想用Selenium Java实例化一个PhantomJS驱动程序。下面是代码:Selenium - Java:PhantomJS:引起:java.lang.ClassNotFoundException:org.openqa.selenium.remote.HttpVerb

 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");   

我与不同版本的硒的尝试和我收到了同样的异常:

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) 

我用我的项目依赖的文章:

  1. phantomjsdriver
  2. 硒 - common.jar
  3. 硒-java的2.5 3.1。 jar

我使用过期版本的硒库的原因是由于我在互联网上发现的一些文章说远程/ HttpVerb已被弃用,降级库会删除错误。不过,我仍然得到这个错误

+0

是乌尔问题就迎刃而解了? – iamsankalp89

回答

1

请POM检查此扶养

<dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-remote-driver</artifactId> 
      <version>2.53.1</version> 
    </dependency> 

检查该类是否存在或不

+0

感谢您的回应。不幸的是,我添加了依赖项,仍然无法工作。 –

+0

它适合你吗?我已经使用了2.48.2独立jar,它正在启动 – iamsankalp89

+0

我检查了库中的HttpVerb类。它不存在。不,仍然存在这个问题。 –