C# Selenium Webdriver 异常 |此版本的 ChromeDriver 仅支持 Chrome 85 版

标签 c# selenium selenium-webdriver selenium-chromedriver

MyChromeDriver
我的谷歌浏览器版本: 88.0.4324.150
我找到了一些 solutions但对我不起作用。
我想打开谷歌浏览器扔 Selenium,但它不起作用。
错误

System.InvalidOperationException
  HResult=0x80131509
  Message=session not created: This version of ChromeDriver only supports Chrome version 85 (SessionNotCreated)
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at RSelenium.start_Browser() in C:\Users\ruper\source\repos\T\T\RSelenium.cs:line 30
   at T.Form1.btn_selenium_Click(Object sender, EventArgs e) in C:\Users\ruper\source\repos\T\T\Form1.cs:line 61
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at T.Program.Main() in C:\Users\ruper\source\repos\T\T\Program.cs:line 47

代码
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"C:\Program Files\Google\Chrome\Application\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.AddArguments("start-maximized");
options.AddArguments("disable-infobars");
options.AddArguments("--disable-extensions");
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-dev-shm-usage");
options.AddArguments("--no-sandbox");
IWebDriver driver = new ChromeDriver(options);

最佳答案

http://chromedriver.chromium.org/downloads?tmpl=%2Fsystem%2Fapp%2Ftemplates%2Fprint%2F&showPrintDialog=1
从这里下载 chrome 驱动程序 88
https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Chrome_ChromeDriver.htm
你可以看到构造函数接受了可执行文件的路径
所以用

IWebDriver driver = new ChromeDriver("c:/DownloadeddirectoryPath",options);
注:路径应该是包含 chromedriver.exe 的目录的 PATH 而不是 chromedriver.exe 本身

关于C# Selenium Webdriver 异常 |此版本的 ChromeDriver 仅支持 Chrome 85 版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66075374/

相关文章:

java - By.xpath(contains(text(), "Some text") 给出错误

c# - RegisterPerWebRequest 已过时,我可以使用 Lifestyle.Scoped 吗?

c# - 用于连接到 Bugzilla 的 .NET API

java - 如何根据子图像元素单击父元素

python - Selenium 无法定位元素(Python)WebScraping

javascript - 使用 Protractor 在 Firefox 上下载文件

python - Selenium 使用 Python : enter/provide http proxy password for firefox

c# - TPL 能否在多个线程上运行任务?

c# - 无法从 Dictionary 转换为 IDictionary

python - 如何在 Django 中为简单用户和 super 用户编写测试用例