Issue
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
Solution
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:
- https://stackoverflow.com/a/76912466/7598774
- https://stackoverflow.com/a/76927754/7598774
- https://stackoverflow.com/a/76929533/7598774
- https://stackoverflow.com/a/76463081/7598774
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.