0

I have Google Chrome already opened where I am doing my own work. I am trying to run a Selenium Chrome driver using the default configuration stored in my C:\\Users\\Himanshu Poddar\\AppData\\Local\\Google\\Chrome\\User Data ddirectory.

But when I am launching Chrome using this default profile, my function never returns which I think is due to my another Chrome window opened on which I am working. Because I can see an alert appearing on my working Chrome window which says "chrome is controlled by test software".

Here is what I have tried

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\Himanshu Poddar\\AppData\\Local\\Google\\Chrome\\User Data")
chrome_path = r"C:\Users\Himanshu Poddar\Desktop\chromedriver.exe"
# This never returns
wd = webdriver.Chrome(chrome_path, chrome_options=options)

The last executing statement webdriver.Chrome never return and prints this to the console

[5972:6048:0614/210846.434:ERROR:cache_util_win.cc(21)] Unable to move the cache: 0
[5972:6048:0614/210846.435:ERROR:cache_util.cc(141)] Unable to move cache folder C:\Users\Himanshu Poddar\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\Users\Himanshu Poddar\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000
[5972:6048:0614/210846.435:ERROR:disk_cache.cc(185)] Unable to create cache
[5972:6048:0614/210846.435:ERROR:shader_disk_cache.cc(623)] Shader Cache Creation failed: -2
Opening in existing browser session.

What was expected:

A different instance of Chrome to be running with the same default profile that is independent of my current chrome window on which I am working.

Note that I tried the suggestions that I was getting for this question and none of them worked for me.

Edit

This issue is somewhat similar to mine but does not contains the solution to this problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Himanshu Poddar
  • 7,112
  • 10
  • 47
  • 93
  • ChromeDriver and Chrome version? – undetected Selenium Jun 14 '19 at 16:53
  • Never tried this before, but I believe you'll need to copy the current profile and write it to another folder yourself. Then pass the new folder's path. (This may fail if Chrome is currently running and using that profile.) – pcalkins Jun 14 '19 at 16:58
  • @DebanjanB ChromeDriver version 2.38 and chrome version 74.0 – Himanshu Poddar Jun 14 '19 at 17:01
  • @pcalkins Copied my profile to other directory and then supplied this path to chrome option but it isn't working – Himanshu Poddar Jun 14 '19 at 17:05
  • ChromeDriver should be 74 to match current Chrome version. Seems like that would throw another error though. – pcalkins Jun 14 '19 at 17:08
  • @pcalkins I think I installed this version last year. How come in one year they updated it from 2 to 74 – Himanshu Poddar Jun 14 '19 at 17:11
  • they've switched so you need a different driver per major version. (kind of a bummer really...) If you go to Help>About Chrome right now, it'll probably already update to v75... so beware. – pcalkins Jun 14 '19 at 17:15
  • It did not help I updated it but its still attaching to its already opened chrome window I am working on – Himanshu Poddar Jun 14 '19 at 17:19
  • @pcalkins Wait actually it did help. I copied the original profile to other directory but I also had to delete some files eg cookies, current status file for the chrome window that I opened. After deleting these files and supplying the path to new profile it worked. Thank you so much. Moreover please note that although I updated my driver but its working with the previous version too. So I think update wasn't necessary. – Himanshu Poddar Jun 14 '19 at 17:33

1 Answers1

1

Thanks to @pcalkins I was able to find an answer for the question. The very first step was to clone your User profile or whatever was there in C:\\Users\\Himanshu Poddar\\AppData\\Local\\Google\\Chrome\\User Data and rename it with some name. In my case I just renamed it with User data - Copy. Next step involves deleting the files that our current user who is using google chrome (in other window) from our cloned copy. Finally run the code as

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
chrome_path = r"C:\Users\Himanshu Poddar\Desktop\chromedriver.exe"
options = Options()
# new clone copy of user data supplied
options.add_argument("user-data-dir=C:\\Users\\Himanshu Poddar\\AppData\\Local\\Google\\Chrome\\User Data - copy")
wd = webdriver.Chrome(chrome_path, chrome_options=options)

Note that the update to my driver wasn't required in this case but its always a good practice to work with latest stable release of the software who knows what dependency problem you may run into.

Though I have cloned the profile and then supplied it to my function. Any answer that does not require copy to be generated and solves it just by including, tweaking, twisting any parameter will be accepted.

Himanshu Poddar
  • 7,112
  • 10
  • 47
  • 93