Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Automatically Download chromedriver that supports the currently installed version of chrome

Writer Sebastian Wright

I'm trying to download Chromedriver into the current directory. I've tried chromedriver-auto installer and get_chrome_driver library. But, I can't download it into the specific directory.

This is my code.

from get_chrome_driver import GetChromeDriver
get_driver = GetChromeDriver()
get_driver.auto_download(extract=True, output_path="")

and I got this

PS D:\Project\Python\Automation\Socinet> & C:/Python37/python.exe d:/Project/Python/Automation/Socinet/chromedriver.py
Traceback (most recent call last): File "d:/Project/Python/Automation/Socinet/chromedriver.py", line 4, in <module> get_driver.auto_download(extract=True, output_path="")
TypeError: auto_download() got an unexpected keyword argument 'output_path'
PS D:\Project\Python\Automation\Socinet> 

What should I do?

1

2 Answers

First run:

pip install get-chrome-driver --upgrade

then give dot if you want to download to currrent directory

get_driver.auto_download(extract=True, output_path=".")

You could use this solution. It will do two things:

  1. Check locally in your computer for the driver version and compare it with the latest version available online.
  2. The latest online version will be downloaded if it does not match your local version.
from selenium import webdriver
import requests
import zipfile
import wget
import subprocess
import os
CHROMEDRIVER_PATH = "" # Insert your Chromedriver path here
CHROMEDRIVER_FOLDER = os.path.dirname(CHROMEDRIVER_PATH)
LATEST_DRIVER_URL = ""
def download_latest_version(version_number): print("Attempting to download latest driver online......") download_url = "" + version_number + "/chromedriver_win32.zip" # download zip file latest_driver_zip = wget.download(download_url, out=CHROMEDRIVER_FOLDER) # read & extract the zip file with zipfile.ZipFile(latest_driver_zip, 'r') as downloaded_zip: # You can chose the folder path to extract to below: downloaded_zip.extractall(path=CHROMEDRIVER_FOLDER) # delete the zip file downloaded above os.remove(latest_driver_zip)
def check_driver(): # run cmd line to check for existing web-driver version locally cmd_run = subprocess.run("chromedriver --version", capture_output=True, text=True) # Extract driver version as string from terminal output local_driver_version = cmd_run.stdout.split()[1] print(f"Local driver version: {local_driver_version}") # check for latest chromedriver version online response = requests.get(LATEST_DRIVER_URL) online_driver_version = response.text print(f"Latest online chromedriver version: {online_driver_version}") if local_driver_version == online_driver_version: return True else: download_latest_version(online_driver_version)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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