4

Every now and then when the Chrome is updated, the existing chrome driver used in the script becomes invalid and the below error message is displayed:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 77

I have to manually update the chrome-driver in the written script. Is there any way to update it automatically with the updated chrome version?

  • 1
    Which dependency management tool do you use? – João Farias Dec 22 '19 at 11:17
  • Currently not using any dependency tool. I am writing the script in Python. Can you mention any tool that can be used. – Divya Anchan Jan 9 at 7:20
3

Welcome.

Yes, it can be done. You need to follow these steps: https://chromedriver.chromium.org/downloads/version-selection And you need to choose a tool in which you implement them.

Let's have a look at a few lines in Python, I'll outline the main flow and you might want to build it more powerful (like command line parameters etc.)

First I'll import requests:

import requests

Then I'll save the necessary links into two varibles + I define the file name of the desired version of chrome driver:

url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'
url_file = 'https://chromedriver.storage.googleapis.com/'
file_name = 'chromedriver_linux64.zip'

Now I'll let the user choose a version, and I get the version from the site:

version = input()
version_response = requests.get(url + version)

Finally, it's time to download the zip file (if it exists):

if version_response.text:
    file = requests.get(url_file + version_response.text + '/' + file_name)
    with open(file_name, "wb") as code:
        code.write(file.content)

The result of these steps will be a zip file with a chrome driver in the current directory (from where you ran the script). You also might use zipfile library to extract the zip file after a successful download.

If you want to fully automate this, you probably need to built in command line parameters and pipe chrome version into your Python script. E.g. in Arch-like systems, you might use $ pacman -Qs chromium for getting Chromium version. Since you don't mention a system architecture on which you want to build this, I've chosen mine.

When ready, you can let it run with cron or similar.

| improve this answer | |
3

Try using webdriver-manager from npm:

https://www.npmjs.com/package/webdriver-manager

And call webdriver-manager update using batch file from your java, python or what ever tool .

To create batch file , open a text file and add webdriver-manager update as the content and now save it as file.bat

| improve this answer | |
0

Use WebdriverManage. It downloads the required Driver binary file (if not present locally) into Cache (default location ~/.m2/repository/webdriver)

And this is how you can add it in your code:

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

latest version dependency :

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.7.1</version>
</dependency>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.