8

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

2
  • Are you sure, when you open Chrome normally, you are logged into Facebook? Commented Dec 23, 2017 at 19:53
  • @ubadub, yes I am, just checked. Commented Dec 23, 2017 at 19:56

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. That seems to open a new window with the right profile, but then it crashes (Message: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.13.2 x86_64))
Ah, I don't really know much about Macs. Is there anything here that helps: sites.google.com/a/chromium.org/chromedriver/help/… . And maybe disable all extensions, see if that helps.
Linux ubuntu: '/home/<usr_name>/.config/google-chrome/Default'
For me, it works chrome_options.add_argument("user-data-dir=/Users/username/Library/Application Support/Google/Chrome/profileName")
this also works for me, and i can start more than one webdriver with it, but it does give an error.
4

As an addition to EnergyNumbers' answer, you also have to make sure that you've actually quit chrome before launching your script.

In my case I constantly got the error Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist)

But that instantly disappeared when I quit chrome before launching the script. Apparantly, no 2 instances of the same profile can be opened at the same time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.