Skip to content Skip to sidebar Skip to footer

Webdriverexception When Starting Chromedriver With User-data-dir Argument

My code: from selenium.webdriver.chrome.options import Options from selenium import webdriver opts = Options() opts.add_argument('user-data-dir=/path/to/profiles_dir/user_id') brow

Solution 1:

There seems to be a bug in chromedriver. I narrowed it down, and two files seem to be the culprit: {user-data-dir}/Local State and {user-data-dir}/{profile-directory}/Preferences. If you do not specify profile-directory, it will be 'Default'.

Chrome/Chromium doesn't seem to be able to read these files, even if you properly close chromedriver, using browser.quit().

You'll need to delete the files in order to be able to start chromedriver again, using the same profile.

I used the following code in my finally block, in order to delete the files:

if browser is not None:
    browser.quit()
    time.sleep(1)
delete_paths = ['../selenium/chrome_profile/Local State',
                '../selenium/chrome_profile/Default/Preferences']
for delete_path in delete_paths:
    if os.path.exists(delete_path):
        os.remove(delete_path)

Post a Comment for "Webdriverexception When Starting Chromedriver With User-data-dir Argument"