Automatic installation of the Chrome driver for the Chrome version

Viewed 2746

If the version of the chrome driver is different from the current chrome version, I want to write a python code that downloads and operates the chrome driver that matches the current chrome version.

This is all I've been looking for

driver = webdriver.Chrome(ChromeDriverManage().install(), chrome_options=chrome_options)

I think this code is inefficient because i have to install the chrome driver every time. Is there any way?

4 Answers

This is what the official docs says :

you can do

pip install chromedriver-autoinstaller

or

Import

import chromedriver_autoinstaller

Code :

from selenium import webdriver
import chromedriver_autoinstaller


chromedriver_autoinstaller.install()  # Check if the current version of chromedriver exists
                                      # and if it doesn't exist, download it automatically,
                                      # then add chromedriver to path

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title

Reference : click here

The chromedriver-autoinstaller library has worked well for me and uses a cache so it doesn't needlessly redownload the driver.

Try to use this script. It will work

from selenium import webdriver
import zipfile
import requests

try:
    version = requests.get('https://chromedriver.storage.googleapis.com/LATEST_RELEASE').text
    url = 'https://chromedriver.storage.googleapis.com/{0}/{1}'.format(version, 'chromedriver_win32.zip')
    r = requests.get(url, allow_redirects=True)
    open('chromedriver.zip', 'wb').write(r.content)
    with zipfile.ZipFile("chromedriver.zip", "r") as zip_ref:
        zip_ref.extractall()
except:
    pass

webdriver-auto-update

There is a package in PyPI and GitHub called webdriver-auto-update. It will detect the driver version on your computer and download the latest chrome driver version/release automatically.

Installation:

Make sure you have Python installed in your system. Run the following in your terminal to install:

pip install webdriver-auto-update

Example

from selenium import webdriver
from webdriver_auto_update import check_driver


# Pass in the folder used for storing/downloading chromedriver
check_driver('folder/path/of/your/chromedriver')

driver = webdriver.Chrome()
driver.get("http://www.python.org")

Reference link:

https://pypi.org/project/webdriver-auto-update/ https://github.com/competencytestlvl/webdriver_auto_update

Related