Selenium Webdriver using default option never retu

2019-08-17 02:13发布

This question already has an answer here:

So 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.

Any help would be highly appreciated. Note that I tried all 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.

1条回答
时光不老,我们不散
2楼-- · 2019-08-17 02:40

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.

查看更多
登录 后发表回答