1
Answer

Invalid OperationException

Ramco Ramco

Ramco Ramco

Aug 04
317
1

Hi

  I am getting error - InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 123
Current browser version is 127.0.6533.89 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe (SessionNotCreated)

static async Task SingleVideo0()
        {
            {
                using (IWebDriver driver = new ChromeDriver())
                {
                    driver.Navigate().GoToUrl("google.com");

                    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

                                        var playButtons = wait.Until(_driver => _driver.FindElements(By.ClassName("video-play-button")));

                    foreach (var playButton in playButtons)
                    {
                        playButton.Click();
                        System.Threading.Thread.Sleep(2000);
                    }
                }
            }
        }
C#

Thanks

Answers (1)
4
Abhishek  Yadav

Abhishek Yadav

106 17.2k 347.9k Aug 04

It looks like the ChromeDriver version you're using is not compatible with your current version of Chrome. You need to update your ChromeDriver to match your Chrome browser version. Here’s how you can do it:

  1. Download the Compatible ChromeDriver:

    • Visit the ChromeDriver download page.
    • Find the version of ChromeDriver that matches your Chrome browser version (127.0.6533.89).
  2. Update ChromeDriver in Your Project:

    • Replace the existing chromedriver.exe file in your project or system with the newly downloaded one.
    • Ensure that the chromedriver.exe is in your project directory or in a location that is included in your system's PATH environment variable.
  3. Verify Compatibility:

    • Ensure that the ChromeDriver version and the Chrome browser version are both up-to-date and compatible with each other.

Here's an updated version of your method to include proper disposal of WebDriver:

static async Task SingleVideo0()
{
    using (IWebDriver driver = new ChromeDriver())
    {
        driver.Navigate().GoToUrl("https://www.google.com");

        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        var playButtons = wait.Until(_driver => _driver.FindElements(By.ClassName("video-play-button")));

        foreach (var playButton in playButtons)
        {
            playButton.Click();
            await Task.Delay(2000); // Use Task.Delay for asynchronous sleep
        }
    }
}

By using await Task.Delay, you ensure that the sleep operation is asynchronous and won't block the thread.

Accepted