Google Chrome cannot read and write to its data directory : selenium

Viewed 5759

Here's the issue i am facing now.

I could launch chrome driver. However my selenium code suddenly doesnt work and pops up above image.

Hope someone can shed light as i couldn't find a solution online. .

4 Answers

Generally BarthRid's answer is correct, providing full path to userdata folder works with Chrome 90+. But if you store userdata folder in the same directory as your script, you can use pathlib to manage things more easily.

import pathlib

script_directory = pathlib.Path().absolute()

options.add_argument(f"user-data-dir={script_directory}\\userdata")

This way allows you to store actual script's directory in a variable, and via formatted string put it in selenium's options argument. Useful while dealing with multiple instances.

I had a similar problem to yours and @scott degen. options.add_argument line of your pasted screenshot

I changed mine from:

options.add_argument("user-data-dir=selenium")

to the full directory, and it seems to be working better now.

options.add_argument("user-data-dir=C:\environments\selenium")

I changed mine from:

options.add_argument("user-data-dir=selenium")

to the full directory, and it seems to be working better now.

dir_path = os.getcwd()
chrome_option.add_argument(f'user-data-dir={dir_path}/selenium')

It seems Chrome changes its Current Working Directory during startup and so the relative path won't work. You can try to convert the user-data-dir to absolute path then pass to chrome. See Bug: 1058347

Related