1

I am just invoking a chrome browser by entering a URL of the page. It opens a browser and closes immediately. However, I have added the dependencies on the POM.xml file.

You can find the code below,


    package com.Rezaid.webdriver;
    
    
    import org.openqa.selenium.chrome.ChromeDriver;
    
    
    public class OpenBrowser {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            System.setProperty("webdriver.chrome.driver", "C://Users//BiTS//Downloads//chromedrivers//chromedriver.exe");
            
              ChromeDriver driver = new ChromeDriver();
                
                driver.get("https://www.google.com");
                
                System.out.println(driver.getCurrentUrl());
    }

I want you to tell me the solution so that I can run the code.

The errors are shown below,

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.
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 10550
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
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.111 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe 
Yaroslavm
  • 1,762
  • 2
  • 7
  • 15

3 Answers3

1

You can use WebDriverManager.chromedriver().setup(); to initiate the Chrome browser and use below in your pom file

<dependencies>
<!-- Other dependencies -->

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>4.11.0</version>
</dependency>
O_K
  • 922
  • 9
  • 14
1

Not sure which version of selenium you are using, since the chrome version in your system is 116, you need to upgrade your selenium to latest one which is 4.11.0. Check below:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.11.0</version>
</dependency>

And once you have upgraded, setting System.setProperty path is no longer mandatory, you can skip that line. Selenium will internally download and manage the drivers for you. Code can be simplified as below:

public static void main(String[] args) {
    // TODO Auto-generated method stub        
    ChromeDriver driver = new ChromeDriver();
    driver.get("https://www.google.com");
    System.out.println(driver.getCurrentUrl());
}

Refer these answers for questions with similar issues:

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

you should update the selenium version to 4.11

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 31 '23 at 08:26