2

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 Profile 1 opens successfully. But when I try to open the second instance of Chrome with Profile 2, I get an error.

Here's my Python code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

#Profile Directory for Google Chrome
dataDir = "--user-data-dir=C:\\Users\\Myname\\AppData\\Local\\Google\\Chrome\\User Data"

#Setting the Chrome options for Profile 1
chrome_options1 = Options()
chrome_options1.add_argument(dataDir)
chrome_options1.add_argument("--profile-directory=Profile 1")
driver1 = webdriver.Chrome(chrome_options=chrome_options1)

#This opens www.google.com sucessfully
driver1.get('https://www.google.com')


#Setting the Chrome options for Profile 2
chrome_options2 = Options()
chrome_options2.add_argument(dataDir)
chrome_options2.add_argument("--profile-directory=Profile 2")
#The below line throws an error (Cannot move the Shared Cache)
driver2 = webdriver.Chrome(chrome_options=chrome_options2)

#This line is not reached as there is error in creating driver2 itself 
driver2.get('https://www.google.com')

Here's the error I'm getting:

[1076:11808:0716/182552:ERROR:cache_util_win.cc(20)] Unable to move the cache: 0

[1076:11808:0716/182552:ERROR:cache_util.cc(134)] Unable to move cache folder C:
\Users\Myname\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\U
sers\Myname\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000

[1076:11808:0716/182552:ERROR:cache_creator.cc(129)] Unable to create cache
[1076:11808:0716/182552:ERROR:shader_disk_cache.cc(589)] Shader Cache Creation failed: -2

I think the error is because the first instance of chrome has locked the shared cache folder (for writing). Therefore, When the second instance tries to open the same shared folder it throws an error.

Is there any workaround for this?

My goal is to open two Chrome instances with two different Profiles simultaneously.

Any help is Appreciated.

Srinidhi Shankar
  • 311
  • 5
  • 15

1 Answers1

6

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 Solution:

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.

thankyouSO
  • 98
  • 1
  • 8
  • Thanks that worked! Here's what I did. Like you mentioned, I separated the Profile folders (Profile1 and Profile2) and placed them in different parent folders. When I ran the Python script to open two Chrome instances with these Profile paths, it automatically created the shared folder (ShaderCache). – Srinidhi Shankar Jan 02 '17 at 06:19