![](/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.