Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open chrome with default user profile using python and selenium on mac

I am trying to get Selenium to open Chrome just as if I was opening it myself, i.e. I should be logged into my accounts like Facebook.

I have the following code:

def startChrome():
    options = webdriver.ChromeOptions() 
    options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")
    driver = webdriver.Chrome(chrome_options=options)
    driver.set_page_load_timeout(60)
    return driver

driver = startChrome()
url = 'https://www.facebook.com'
driver.get(url)

However this gets me to Facebook without being logged in. I have checked chrome://version and the profile URL is in fact correct. What am I doing wrong?

Using Python 3, Chrome Version 63.0.3239.84, MacOS High Sierra

like image 259
Alexis Eggermont Avatar asked Dec 23 '17 18:12

Alexis Eggermont


Video Answer


1 Answers

Remove the Default/ from the end of your path

options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/")

On a PC, it would typically be something like:

options.add_argument('user-data-dir=C:/Users/{USERNAME}/AppData/Local/Google/Chrome/User Data')

You'll need to check you've got compatible versions of chromedriver and chrome - the easiest way to do that, is to check that both are up to date.

If it crashes immediately on opening, check the chromedriver help page. Maybe try disabling all extensions, to see if that helps.

like image 79
410 gone Avatar answered Oct 03 '22 13:10

410 gone