Automatic installation of the Chrome driver for the Chrome version

Question:

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?

Asked By: kwsong0314

||

Answers:

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

Answered By: Matthew Hamilton

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
Answered By: MananPyJava

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

Answered By: cruisepandey

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

Answered By: Competency Test

I did a quick comparison of the three different "auto-update" python packages mentioned on this stackoverflow.com page to see which package(s) will be worth investing my time to use for my applications. I need something to build into my libraries, because chromedriver’s intentional monthly obsolescence is such a maintenance nightmare.

When evaluating open source packages, I look at 1) overall code quality, 2) maintenance, 3) # professional programmers who depend on it, 4) # maintainers, 5) related or derived dependent packages, 6) documentation and usage examples available now, 7) whether there are conda and pip versions available, and 8) any other factors or "issues" that indicate product maturity or quality of support (or lack thereof).

"Popularity" by itself is not sufficient to merit investment, for example, it is easy to be misled by popularity; witness Amazon.com "fake" product reviews).

chromedriver-autoinstaller: version = "0.4.0", updated 2 months ago. |
(3.2K users, 132 stars, 44 forks, 8 contributors)

webdriver_auto_update | version = "0.1.0", updated 28 days ago.
| (# users UNKNOWN, 7 stars, 3 forks, 2 contributors)

The chromedriver-autoinstaller author/maintainer is also the author/maintainer of the geckodriver-autoinstaller package.

For consistent comparison with chromedriver-autoinstaller and the others:

geckodriver-autoinstaller: |
version = "0.1.0", updated 3 yrs ago (not great). |
(304 users, 19 stars, 16 forks, 2 contributors)

chromedriver-autoinstaller has the largest user base of 3200 users, and largest number of forks.

Answered By: Rich Lysakowski PhD