1

In my machine the version of the Chrome Browser is Version 78.0.3904.108.

And following is the code I used to run the selenium script in the chrome browser.

System.setProperty("webdriver.chrome.driver", "C:\\Users\\ChampWk21\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

Following is the Exception I got when I try to run the code:

Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 27833
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 74
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.66 seconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'DESKTOP-BHL4HJ3', ip: '192.168.1.16', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: driver.version: ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at WDSel.main(WDSel.java:12)

I have developed a framework for UI Testing. And this error occurred because of chrome driver version is not compatible with the Chrome Browser. So I have to use the chrome driver version which is suiting for the current version of the Chrome Browser.

My Question is when the version of the Chrome Browser is changing time to time do we have to download the chrome driver which is suiting for the exact version of the Chrome browser. Aren't there other ways to handle it. Specially when comes to a framework use, can't we implement a way to automatically update the drivers instead of manually download the drivers and set the path.

Thanks.

AndiCover
  • 1,724
  • 3
  • 17
  • 38
pramod_maddu
  • 93
  • 1
  • 8
  • Check you google chrome browser version and download compatible chromedriver.exe – Nik Dec 17 '19 at 06:41

1 Answers1

1

You can automatically download the correct driver by using the WebDriverManager. It downloads the correct driver version for your used Browser version.

I am using this for more than a year with Chrome autoupdate on more than 80 Hosts and it works without any problems.


Just use following line before initializing the ChromeDriver (Works for other drivers too):

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

It would be the best to include the library by using Gradle or Maven.

Maven

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.7.1</version>
    <scope>test</scope>
</dependency>

Gradle

dependencies {
    testCompile("io.github.bonigarcia:webdrivermanager:3.7.1")
}

There are similar libraries available for other languages e.g. Python.

AndiCover
  • 1,724
  • 3
  • 17
  • 38
  • Thanks @AndiCover for answering this question. I try this and it solved the above matter, but now I get a different kind of Exception as follows. – pramod_maddu Dec 17 '19 at 08:35
  • `[main] WARN io.github.bonigarcia.wdm.WebDriverManager - The driver version for Google Chrome 78 is unknown ... trying with latest [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://chromedriver.storage.googleapis.com/ to seek chromedriver [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Latest version of chromedriver is 79.0.3945.36 [main] INFO io.github.bonigarcia.wdm.Downloader - Downloading https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_win32.zip` – pramod_maddu Dec 17 '19 at 08:36
  • Could you please share your expertise on it. Thanks – pramod_maddu Dec 17 '19 at 08:37
  • Please make sure to use the latest version of WebDriverManager. – AndiCover Dec 17 '19 at 10:12