Skip to content Skip to sidebar Skip to footer

Cannot Open Two Google Chrome Instances With Different Profiles Using Selenium Web Driver For Chrome In Python

I am using Selenium WebDriver for Chrome to open two instances of Google Chrome with two different Profiles (Profile 1 and Profile 2) simultaneously. The first instance with Profil

Solution 1:

I don't know if this is still relevant to you and if my solution also works for you as you used Python whereas I use R.

I have written a code for automated web-scraping in R using the RSelenium package with Chrome web-driver. Just as you, I wanted to simultaneously use multiple instances of Google Chrome with different Google Chrome Profiles, say "Profile 1" and "Profile 2", and I created them in Google Chrome accordingly. R let me easily open a selenium web-driver with one of the two profiles, e.g. "Profile 1" (remember this is R):

# Define profile directory:
prof1 <- getChromeProfile("~/Users/<username>/AppData/Local/Google/Chrome/User Data", "Profile 1") 

#Set up remote driver with according chrome profile (prof1):
remDr <- remoteDriver(browserName = "chrome", extraCapabilities = prof1) 

#Open remote driver:
remDr$open()

...but never both Google Chrome profiles at the same time. To be precise, as soon as I opened a second instance of chrome with the second profile, i.e. "Profile 2", my console as well as both web-drivers froze and did not recover any more.

My Answer :

The solution was quite simple: I moved both Google Chrome profile folders ("Profile 1" and "Profile 2") from their default location (where Google Chrome created them) to a different directory on my computer and stored them in a newly created parent folder. Let me provide an example:

Default google chrome profile locations ("Profile 1" and "Profile 2", created by Google Chrome):

"~/Users/<username>/AppData/Local/Google/Chrome/User Data/Profile 1""~/Users/<username>/AppData/Local/Google/Chrome/User Data/Profile 2"

I moved them to my "Documents" folder into new parent folders:

"~/Users/<username>/Documents/Google Chrome Profile 1/Profile 1""~/Users/<username>/Documents/Google Chrome Profile 2/Profile 2"

The new folders "Google Chrome Profile 1" and "Google Chrome Profile 2"are the before mentioned parent folders.

Why does this work?

It seems to me that per default Google Chrome not only uses profile information from the respective profile folders but also from the "shared" location in the parent folder. If two (or more) profiles run information from such a shared folder, it can get messy, the corresponding web-drivers get stuck and the console throws an error.

This is why in the new location I saved the profile folders in the new parent folders "Google Chrome Profile 1" and "Google Chrome Profile 2". Like this I manage to run 4 independent chrome instances with different profiles in parallel (all of them with their own cookies and history).

I hope this works for you.

Post a Comment for "Cannot Open Two Google Chrome Instances With Different Profiles Using Selenium Web Driver For Chrome In Python"