Search code examples
pythonselenium-webdriverselenium-chromedriver

Python, Selenium, Chrome: How to set driver location in Selenium 4.12


Use case scenario

Selenium 4.12 (Chrome driver) behind proxy authentication and no access to github.io.

Problem

Somewhere along the way, executable_path arg in webdriver.Chrome method was deprecated. Instead, webdrive_manager.chrome module tries to download chromedrive.exe. In order to select driver version, it access https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json which I can't access due to company policies, therefore throwing an error.

Question

How to pass chromedriver.exe path to webdriver.Chrome() with selenium 4.12?


Solution

  • You have to use Service class now to pass the executable_path

    Refer the below code, this is how you can do it:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    
    service = Service(executable_path="C:/<fullpath>/chromedriver.exe")
    driver = webdriver.Chrome(service=service)
    driver.get("https://google.com")