1

I am trying to load a profile to selenium so that I don't have to keep log in to the website that selenium is about to visit. I am running it with Python on my Mac.

In the Firefox version, I use the below code:

def create_selenium_FF():
    profile = webdriver.FirefoxProfile('/Users/Victor/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
    driver = webdriver.Firefox(profile)
    return driver

It can successfully start Firefox, but it doesn't have the log in info of the website that it visits, however I check in the automated Firefox browser using about:profiles, it does recognise the profile that I feed it.

In the Chrome version, I use the below code, notice I make a local copy of the profile already.

def create_selenium_chrome():
    DRIVER = 'chromedriver'
    options = webdriver.ChromeOptions()
    options.add_argument("--user-data-dir=/Users/Victor/Library/Application Support/Google/Chrome2")
    options.add_argument("--profile-directory=Default")
    driver = webdriver.Chrome(DRIVER, options=options)
    return driver   

It can also start Chrome, and looks like it has my profile, but it raises an error:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

How can I get it working please?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Victor
  • 659
  • 3
  • 8
  • 19

1 Answers1

2

I just solved the problem !

So here is my code :

from selenium import webdriver
options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\Users\\%username%\\AppData\\Local\\Google\\Chrome\\User Data 2")
driver = webdriver.Chrome(executable_path=path,options=options)
driver.get("https://www.google.com") 

The thing is, you'll get this error if there already is chrome opened on your computer !

So, i just copy / paste the folder User Data and rename the pasted one into User Data 2 so my chrome works with user data and selenium with user data 2 I guess.

I know that you've been waiting for a long time and I don't know if u still need this but here you got !!

Madar
  • 196
  • 2
  • 15