2017-07-17 101 views
0

運行下面的代碼時,我觀察到org.openqa.selenium.WebDriverException: unknown error異常。如何解決org.openqa.selenium.WebDriverException:未知錯誤

我不明白爲什麼會出現此錯誤,即使我使用簡單的驅動程序初始化代碼。

我使用Eclipse火星2.

我用下面的代碼:

import org.openqa.selenium.*; 
    import org.openqa.selenium.chrome.*; 

    public class APP { 

     public static void main(String[] args) 
     { 
      // TODO Auto-generated method stub 

      System.setProperty("webdriver.chrome.driver", "E:\\CDS\\Application\\chromedriver.exe"); 
      try { 
       WebDriver driver = new ChromeDriver(); 
       driver.get("http://www.google.com"); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       System.out.println(e); 
      } 
     } 
    } 

返回該錯誤

enter image description here

請指引我解決它的辦法。

+0

鉻合金驅動程序版本是2.30。你正在使用最新的Chrome瀏覽器? –

+0

我使用的是Chrome版本58.19.3029.110 –

+0

這很奇怪...代碼看起來不錯。你可以嘗試添加一些隱含的等待並嘗試?此外,嘗試下載chromedriver 2.29和檢查 –

回答

0

看來ChromeDriver不能使用默認ChromeOptions。 您可以使用下面的代碼來初始化WebDriver

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.chrome.ChromeOptions; 

    public class APP { 

     public static void main(String[] args) 
     { 
      // TODO Auto-generated method stub 

      System.setProperty("webdriver.chrome.driver", "E:\\CDS\\Application\\chromedriver.exe"); 
      try { 
       ChromeOptions options = new ChromeOptions(); 
       options.addArguments("--disable-notifications"); 
       WebDriver driver = new ChromeDriver(options); 
       driver.get("http://www.google.com"); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       System.out.println(e); 
      } 
     } 
    } 

讓我知道了狀態,無論是爲你工作或沒有。

+0

同樣的錯誤在線WebDriver driver = new ChromeDriver(options); –

+0

您是否僅導入需要的導入,不導入使用。*? import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; –

+0

我做到了這一點,仍然是一樣的錯誤。 –