Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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. .

like image 905
user15722469 Avatar asked Apr 21 '21 14:04

user15722469


3 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.

like image 170
Freese Avatar answered Oct 13 '22 12:10

Freese


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")
like image 4
BarthRid Avatar answered Oct 13 '22 10:10

BarthRid


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')
like image 3
alireza jahani Avatar answered Oct 13 '22 12:10

alireza jahani