2017-09-19 46 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類。它不存在。不,仍然存在這個問題。 –