pythonselenium-chromedriverwebdriver-manager

webdriver-manager getting error as executable


I have a python script which uses ChromeDriverManager().install() for getting the latest chromedriver.

A snippet of the code:

def get_location():
    exe_path = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"

    service = Service(ChromeDriverManager().install())
    options = Options()
    options.add_argument('--headless=new')
    options.binary_location = exe_path

    service.creation_flags = CREATE_NO_WINDOW

    driver = webdriver.Chrome(service=service, options=options)

Everything works fine when run using the main.py script, no error. But when I convert the python file, main.py to an executable, main.exe using pyinstaller --onefile --noconsole main.py the webdriver manager shows error on the ChromeDriverManager().install() line.

The error is this:

enter image description here

What should I do to avoid this error?


Solution

  • os.environ['WDM_LOG'] = str(logging.NOTSET)
    os.environ['WDM_PROGRESS_BAR'] = str(0)
    

    Add these lines at the beginning of your function. This disables Webdriver-manager logs. The error is caused by not having a console to view the logs.