【问题标题】:Issues with the Chrome Driver with C# Visual StudioC# Visual Studio 的 Chrome 驱动程序问题
【发布时间】:2021-08-06 22:00:54
【问题描述】:

我正在尝试使用 Selenium Web 驱动程序设置 Selenium 测试。我已经在 Visual Studio 上安装了 Selenium 库。

我这里有这段代码:

IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com/");    

我收到此错误:

System.InvalidOperationException : session not created: 此版本的 ChromeDriver 仅支持 Chrome 版本 85 (SessionNotCreated)

堆栈跟踪:

RemoteWebDriver.UnpackAndThrowOnError(响应错误响应)
RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 参数)
RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
ChromeDriver.ctor(ChromeDriverService 服务,ChromeOptions 选项,TimeSpan 命令超时)
ChromeDriver.ctor(ChromeOptions 选项)
ChromeDriver.ctor()
UnitTest1.WebDriverTesting() 第 70 行

我已经检查了我安装的库。它是最新版本的 Chrome 驱动程序 90,并且安装的 Chrome 版本是 90。

任何线索将不胜感激。

谢谢

【问题讨论】:

  • 您安装了 2 个 Chromedriver 有什么原因吗?摆脱最上面的那个。您可能需要进入您的bin 文件夹并手动删除.exe
  • 正如@JD2775 所说。您只需要 1 个 chrome 驱动程序。删除显示 85 的那个。您可能想检查 taskmanage 并杀死所有 chromedriver.exe。还要更改这一行 IWebDriver driver = new ChromeDriver(".");以便它使用 bin chromedriver.exe

标签: c# visual-studio selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

根据我的测试和其他人的建议,您可以尝试以下步骤来解决c#中chrome驱动的问题。

首先,请安装 nuget-package Selenium.WebDriverSelenium.WebDriver.ChromeDriver。(请删除图片中的第一个 nuget-package)

其次,我们可以在packages\Selenium.WebDriver.ChromeDriver.90.0.4430.2400\driver\win32\chromedriver.exe路径下找到chromedriver.exe。

第三,请将chromedriver.exe复制到Project\bin\debug文件夹中。

最后你可以试试下面的代码,用https://www.google.com/的url打开chrome浏览器。

        ChromeDriver driver = new ChromeDriver(".");
        driver.Navigate().GoToUrl("https://www.google.com/");

【讨论】:

  • 嗯,是的,我删除了它。我刚刚在路径中更新了最新的 Chrome 驱动程序并且它工作正常。但我仍然认为你的答案是正确的。
猜你喜欢
  • 1970-01-01
  • 2017-03-20
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
  • 2018-08-30
  • 1970-01-01
  • 2017-04-18
  • 2011-07-17
相关资源
最近更新 更多