正如您的图像显示您已正确安装参考,
但仍然看起来引用存在配置问题,
您需要声明名称空间,然后查看是否出现错误,
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome; // or more specific its ok you get no error till here
我希望选择对你来说是个问题,
那么你还需要在构造函数中提供一些配置选项,
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", "YOUR_DownloadPath");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddArguments("disable-infobars");
然后,使用
try{
IWebDriver Driver = new ChromeDriver(chromeOptions);
}catch(Exception e){Console.writeLine(e);}
您需要将代码放入 try catch 块中,
因此,您可以获得完整的错误异常跟踪并将其提供给我们。
请问chrome浏览器打开成功了吗?
ok chrome浏览器可以打开,
参考这个,可能是重复的问题,
您的代码使用新的基于 marionette 的 Web 驱动程序而不是 gecko 驱动程序。
Selenium - Visual Studios - C# - 所有(chrome、firefox 和 internet explorer)webdrivers 无法启动驱动程序服务 https://stackoverflow.com/questions/39005512/selenium-visual-studios-c-sharp-all-chrome-firefox-and-internet-explorer
尝试使用 Nuget 包管理器并再次下载程序集引用