0
 <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
    </dependency>
    <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.2</version>
    </dependency>
          <dependency>
        <groupId>org.apache.httpcomponents.client5</groupId>
        <artifactId>httpclient5</artifactId>
        <version>5.2.1</version>
    </dependency>

  
  WebDriverManager.chromedriver().setup();        
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("--headless");
        options.addArguments("--user-agent=MiUserAgentPersonalizado");

        WebDriver driver = new ChromeDriver(options);
        driver.get("XXXX");



Exception in thread "main" 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 114 Current browser version is 116.0.5845.96 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

PLEASE, I want to know, How Should I to setting selenium to automatically recognize specify version of Chrome. it worked around two months until yesterday, but today not

Alexander
  • 16,091
  • 5
  • 13
  • 29
JMBLAS
  • 1
  • 3
  • This is probably the answer to your issue in regards to new CfT api for chromedriver releases: https://stackoverflow.com/a/76998277/11543023 – djmonki Aug 29 '23 at 08:13

2 Answers2

0

You can use WebDriverManager to automatically download and set up the appropriate ChromeDriver version based on your installed Chrome browser version.

This way:

// Use the correct version number
WebDriverManager.chromedriver().browserVersion("116.0.5845.96").setup(); 
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
options.addArguments("--headless");
options.addArguments("--user-agent=MiUserAgentPersonalizado");

Remember to replace 116.0.5845.96 with the exact version of Chrome installed on your system.

Diego Borba
  • 1,282
  • 8
  • 22
  • ok, but do i always have to change the version manually? , there is another way, without specifying the version, because chrome will change the version at another time, this application will fail, and changing the version manually adds more maintenance to this application – JMBLAS Aug 18 '23 at 17:03
  • You can use `driver.getCapabilities().getCapability(CapabilityType.VERSION)` and deal with it – Diego Borba Aug 18 '23 at 17:14
0

Using latest version of selenium 4.11.0 solves this problem. And use;

WebDriver driver = new ChromeDriver();
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
Sudhi
  • 7
  • 1
  • 4