当我尝试使用--user-data-dir
让当前用户使用Selenium启动Chrome时,我得到一个错误,如下所示:
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
如何修复此错误?
发布于 2020-02-04 07:29:13
此错误消息...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
ChromeDriver无法使用指定的user data directory
启动新的Chrome浏览器会话,因为它已在使用中。
可以按如下方式重现此错误:
从selenium导入options.add_argument(r"--user-data-dir=C:\Users{}\AppData\Local\Google\Chrome\User驱动程序导入getpass options = webdriver.ChromeOptions() options.add_argument("start-maximized") executable_path=r'C:\WebDrivers\chromedriver.exe') driver.get("https://www.google.com/")
12148:21412:0204/035557.731:ERROR:cache_util_win.cc(21)无法移动缓存:访问被拒绝。(0x5) 12148:21412:0204/035557.731:ERROR:cache_util.cc(141)无法将缓存文件夹C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User Data\ShaderCache\0x5缓存移动到C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User 12148:21412:0204/035557.731:ERROR:disk_cache.cc(178) 12148:21412:0204/035557.731:ERROR:shader_disk_cache.cc Unable to create cache Data\ShaderCache\old_GPUCache_000(605) Shader Cache创建失败:-2在现有浏览器会话中打开。回溯(最近一次调用):文件"C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\yandex_ru.py",行18,in driver = webdriver.Chrome(options=options,"C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py",webdriver.Chrome行81,in __init__ desired_capabilities=desired_capabilities)文件“C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py”,行157,在__init__ response (self.start_session,browser_profile)文件响应行252中,在start_session response= self.execute(Command.NEW_SESSION,parameters)文件响应行321,在execute user (Response)文件"C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py",第242行中,在用户引发selenium.common.exceptions.InvalidArgumentException:(exception_class,screen,stacktrace)消息中,消息:无效参数:用户数据目录已在使用中,请为--user- data -dir参数指定唯一值,或者不要使用user
分析
错误堆栈跟踪清楚地抱怨访问被拒绝,因为程序无法将缓存文件夹..\ShaderCache\GPUCache
移动到..\ShaderCache\old_GPUCache_000
。因此,创建缓存失败,随后创建着色器缓存创建失败。虽然这些问题增加了InvalidArgumentException
,但仍然可以在现有的Chrome浏览器会话中打开一个新窗口。
尽管抛出了错误,但新的Chrome窗口仍然会被启动,但仍然与已经打开的Chrome会话保持连接,但新窗口不能由WebDriver实例控制。因此,您可以在url栏中看到data:,
。
解决方案
你需要注意几件事:
如果您使用默认的Chrome配置文件访问网页,以便在同一测试机器上进行其他工作,则不应将user-data-dir
设置为
中找到
默认数据如果您在隔离的测试系统中执行测试,您可以将user-data-dir
设置为
中找到
中找到
发布于 2020-05-13 03:46:24
最简单和最容易的修复方法是:清除现有打开的chrome驱动程序:步骤如下:在任务栏的搜索窗口中输入任务管理器到Spotlight Search /,或使用其他方式访问任务管理器。当任务管理器向导/窗口弹出时,搜索chromedriver,右键单击它,然后单击"End Task“。就这样。这不是一个永远的解决办法。一旦你打开chrome浏览器多次,你必须做同样的步骤来避免这个问题。希望这有助于我寻找一个稳定的修复。
发布于 2020-07-15 15:47:15
正如Tes answer提到的,我打开了Windows任务管理器,并关闭了所有的chrome.exe和chromedriver.exe进程,它工作了!
我使用以下配置通过我的Chrome配置文件打开了Google Chrome:
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:\\Users\\my_user\\AppData\\Local\\Google\\Chrome\\User Data')
driver = webdriver.Chrome(executable_path='./chromedriver.exe', options=options)
https://stackoverflow.com/questions/59987080
复制相似问题