![](/img/trans.png)
[英]How to fix Exception in thread “main” org.openqa.selenium.WebDriverException?
[英]How to fix the org.openqa.selenium.WebDriverException: unknown error
運行以下代碼時,我觀察到org.openqa.selenium.WebDriverException: unknown error
異常。
即使使用簡單的驅動程序初始化代碼,我也無法理解為什么會發生此錯誤。
我正在使用Eclipse Mars 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);
}
}
}
返回此錯誤
請引導我解決該問題。
看來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);
}
}
}
讓我知道您的狀態,不管它對您是否有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.