C# Selenium Webdriver Exception | This version of ChromeDriver only supports Chrome version 85
Asked Answered
D

3

11

MyChromeDriver

My Google Chrome version: 88.0.4324.150

I found some solutions but the don't worked for me. I want to open Google Chrome throw the Selenium, but it don't work yet.

Error

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

Code

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);
Deontology answered 6/2, 2021 at 9:32 Comment(1)
@PDHide sadly I already dried to Chance the Versions, but this won't solve the ProblemDeontology
C
10

http://chromedriver.chromium.org/downloads?tmpl=%2Fsystem%2Fapp%2Ftemplates%2Fprint%2F&showPrintDialog=1

Download chrome driver 88 from here

https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Chrome_ChromeDriver.htm

you can see the constructor accepts the path of executable

so use

IWebDriver driver = new ChromeDriver("c:/DownloadeddirectoryPath",options);

Note: the path should be PATH to directory containing chromedriver.exe and not the chromedriver.exe itself

Condition answered 6/2, 2021 at 10:46 Comment(5)
Thank you! Worked now. My issue was that I only need to point to the Path, not the .exeDeontology
Glad it helped , reading the class documentation is the best way to know what would be the expected solutionCondition
I was confused and thought I had to download version 85 because of the message, but I needed to download the version which my browser uses.Parlance
You have to run the chromedrive.exe too for it to work.Reparation
@NareshBisht is right. In my case I had to write the whole path including "chromedrive.exe".Viral
V
2

@PDHide's solution had solved my issue, but again I have faced the same problem. And I have solved it like that now:

I have added WebDriverManager from Nuget into my project. I have added this line to onload:

new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);

And I have made a method that returns the WebDriver object:

 public IWebDriver GetChromeDriver()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("no-sandbox");
     string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "/Chrome", "ChromeDriver.exe", SearchOption.AllDirectories);
     List<KeyValuePair<string, DateTime>> lstFile = new List<KeyValuePair<string, DateTime>>();
     foreach (string file in files)
     {
         lstFile.Add(new KeyValuePair<string, DateTime>(file, File.GetLastWriteTime(file)));
     }
     string filePath = System.IO.Path.GetDirectoryName(lstFile.OrderByDescending(r => r.Value).First().Key);
     return new ChromeDriver(filePath, options);
 }

 

And I am calling it like that:

IWebDriver myDriverChrome = new BasicOperations().GetChromeDriver();
Viral answered 14/12, 2023 at 12:52 Comment(0)
G
1

Another way of ensuring that webdriver and Chrome (actually I am suggesting Chromium) versions are the same is to download both from the same Chromium snapshots page. https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html

For Example, v96 Chromium Linux and the respective web driver is here: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/929513/

The build numbers for stable versions could be found here: https://github.com/Bugazelle/chromium-all-old-stable-versions

PDHide already described how to point to the webdriver path. To point to Chromium binary/executable, use

var options = new ChromeOptions();
options.BinaryLocation = "/full/location/including/binary";
var driver = new ChromeDriver("/folder/where/webdriver/located", options);
Giuseppe answered 10/2, 2022 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.