From 409f3feaef8fbae80189d6031916a7a6b9016b92 Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Wed, 27 May 2020 13:49:28 +1000 Subject: [PATCH] Use path to find chromedriver before falling back to platform-specific defaults. Add Mac. --- driver.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/driver.py b/driver.py index 993f363..bd0f528 100644 --- a/driver.py +++ b/driver.py @@ -55,20 +55,20 @@ chrome_options.add_argument('--headless') chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) -if platform.system() == 'Linux': - if os.path.exists("/usr/bin/chromedriver"): - browser = webdriver.Chrome(executable_path="/usr/bin/chromedriver", - options=chrome_options) +chromedriver_path = shutil.which('chromedriver') +if chromedriver_path is None: + if platform.system() == 'Linux': + chromedriver_path = '/usr/bin/chromedriver' + elif platform.system() == 'Darwin': + chromedriver_path = '/usr/local/bin/chromedriver' else: - print("Chromedriver not found; expected path '/usr/bin/chromedriver'") - exit(1) + chromedriver_path = 'C:/ChromeDriver/chromedriver.exe' + +if os.path.exists(chromedriver_path): + browser = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options) else: - if os.path.exists("C:/ChromeDriver/chromedriver.exe"): - browser = webdriver.Chrome(executable_path="C:/ChromeDriver/chromedriver.exe", - options=chrome_options) - else: - print("Chromedriver not found; expected path 'C:/ChromeDriver/chromedriver.exe'") - exit(1) + print("Chromedriver not found; expected path", chromedriver_path) + exit(1) browser.set_page_load_timeout(10000) browser.set_window_size(1366, 768)