1

I am trying to setup a simple program in selenium and run into

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: cannot find Chrome binary.

Please find below sample code and also the error details

@Test
    public void shouldAnswerWithTrue()
    {
        WebDriver driver = new ChromeDriver();
        driver = new ChromeDriver();

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");

        driver.findElement(By.name("q")).sendKeys("YouTube");
        WebElement searchIcon = driver.findElement(By.name("btnK"));
        searchIcon.click();
        assertTrue( true );
    }

After running the above program, I notice the error below:

Aug 02, 2023 9:56:56 PM org.openqa.selenium.manager.SeleniumManager lambda$runCommand$1
WARNING: The chromedriver version (96.0.4664.45) detected in PATH at /usr/local/bin/chromedriver might not be compatible with the detected chrome version (115.0.5790.114); currently, chromedriver 115.0.5790.102 is recommended for chrome 115.*, so it is advised to delete the driver in PATH and retry
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 96
Current browser version is 115.0.5790.114 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Shawn
  • 4,064
  • 2
  • 11
  • 23
JavaMan
  • 465
  • 1
  • 6
  • 21
  • 1
    Try commenting out the `System.setProperty` line. Since you are using selenium `v4.11.0`, setting the driver path is optional now. See if it works after removing `System.setProperty`. Check this answer if it helps - https://stackoverflow.com/a/76463081/7598774 – Shawn Aug 02 '23 at 15:43
  • Thanks @Shawn - I tried running the code after removing set property statement but I still get an error as now it seems the webdrivermanager is stuck at version 96 for chrome. – JavaMan Aug 02 '23 at 16:18
  • Can you edit your question and share your latest code and latest error trace please? – Shawn Aug 02 '23 at 16:25
  • Thanks @Shawn - I have revised the question. It seems this may be specific to mac, but please let me know in case you need further info. Cheers – JavaMan Aug 02 '23 at 16:31
  • 1
    Strange, selenium should have downloaded the latest 115 version `chromedriver.exe` and should have used it. Instead it is still trying to use 96 version driver. Does your laptop have access to internet? Hope no firewalls are blocking? Try deleting the old driver from this path `/usr/local/bin/chromedriver`, and see if that helps selenium to download and use latest chromedriver. – Shawn Aug 02 '23 at 16:39
  • 1
    Thanks a lot @Shawn for your help and responding to my question. I removed the chromedriver from /usr/local/bin/chromedriver and it seem to have worked. Could you please answer my question so that I can mark it as the answer as it would help then help others as well? Many thanks, Cheers – JavaMan Aug 02 '23 at 16:56

3 Answers3

1

This error message...

Aug 02, 2023 9:56:56 PM org.openqa.selenium.manager.SeleniumManager lambda$runCommand$1
WARNING: The chromedriver version (96.0.4664.45) detected in PATH at /usr/local/bin/chromedriver might not be compatible with the detected chrome version (115.0.5790.114); currently, chromedriver 115.0.5790.102 is recommended for chrome 115.*, so it is advised to delete the driver in PATH and retry
...
...
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 96
Current browser version is 115.0.5790.114 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

...implies that the path you have passed through the System.setProperty() line contains ChromeDriver v96.0.4664.45 which is old and ancient where as is of v115.0.


Using Selenium Manager

As you are using Selenium v4.11.0 you can remove the line of code:

System.setProperty("webdriver.chrome.driver","//Users//user//year//TestSelenium//src//test//java//org//example//chromedriver");

Additionally, you need to delete the ChromeDriver v96.0.4664.45 from /usr/local/bin/, so Selenium Manager which is now integrated with Selenium can download the matching ChromeDriver silently in the background and execute the test.

Your effective code block will be:

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks undetected selenium - I removed the set property statement and now I see following error : org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 96 Current browser version is 115.0.5790.114 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome – JavaMan Aug 02 '23 at 15:56
  • @JavaMan Checkout the updated answer and let me know the status. – undetected Selenium Aug 02 '23 at 20:18
1

Since you are on selenium v4.11.1, you don't need to set the chromedriver.exe path manually using System.setProperty, nor you need any third party tool such as WebDriverManager. Selenium has in-built tool known as SeleniumManager will do the driver manamgement automatically.

Regarding your updated ERROR: There is no issue in your code, selenium should download and use latest chromedriver.exe matching the version of your chrome browser which is v115. Somehow, it is still using v96 driver.

Solution: Just delete the old driver(v96) from the cache. i.e. from this path (usr/local/bin/chromedriver). And then let selenium download the latest driver programmatically. This should solve the issue.

Shawn
  • 4,064
  • 2
  • 11
  • 23
1

A new warning message was just added so that people are notified to delete conflicting driver versions in their path: https://github.com/SeleniumHQ/selenium/blob/fbfa5d26ce96ca067d62b6921915e640498e3b09/rust/src/lib.rs#L496

After determining your versions, it will print a message like this: The chromedriver version (114.0.5735.90) detected in PATH at /usr/local/bin/chromedriver might not be compatible with the detected chrome version (115.0.5790.114); currently, chromedriver 115.0.5790.170 is recommended for chrome 115.*, so it is advised to delete the driver in PATH and retry (Assuming you're not masking warnings)

Once these conflicting versions are deleted, Selenium Manager will automatically download drivers to ~/.cache/selenium by default when calling WebDriver driver = new ChromeDriver(); in Java.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48