Reputation: 251
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?
Upvotes: 4
Views: 15592
Reputation: 241
yeongbin-jo hasn't fixed the issue even after 2 weeks. So, I created a fork named chromedriver-autoinstaller-fix
to address this problem.
pip install chromedriver-autoinstaller-fix
from selenium import webdriver
import chromedriver_autoinstaller_fix
chromedriver_autoinstaller_fix.install()
# Check if the current version of chromedriver exists
# and if it doesn't, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
Upvotes: -1
Reputation: 3095
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.
Upvotes: 1
Reputation: 129
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
Upvotes: 0
Reputation: 29362
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
Upvotes: 5
Reputation: 172
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
Upvotes: 0
Reputation: 106
The chromedriver-autoinstaller library has worked well for me and uses a cache so it doesn't needlessly redownload the driver.
Upvotes: 2