import os

import subprocess def get_chrome_version(): try: output = subprocess.check_output(["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--version"]) version = output.decode("utf-8").split()[2] major_version = int(version.split('.')[0]) return major_version except subprocess.CalledProcessError: return None def get_chromedriver_version(): chromedriver_path = os.path.expanduser("~/Downloads/chromedriver") try: output = subprocess.check_output([chromedriver_path, "--version"]) version = output.decode("utf-8").split()[1] major_version = int(version.split('.')[0]) return major_version except (subprocess.CalledProcessError, IndexError): return None chrome_version = get_chrome_version() chromedriver_version = get_chromedriver_version() if chrome_version and chromedriver_version: if str(chromedriver_version) == str(chrome_version + 1): print("Chrome major version:", chrome_version) print("ChromeDriver major version:", chromedriver_version) else: print("The Chrome and ChromeDriver versions are not in the required order.") elif not chrome_version: print("Chrome is not installed or the version cannot be determined.") elif not chromedriver_version: print("ChromeDriver is not installed or the version cannot be determined.")

0 comments:

Post a Comment

 
Top