当我尝试使用 --user-data-dir 让当前用户使用 Selenium 启动 Chrome 时,我收到以下错误:
When I am trying to use --user-data-dir for the current user to start Chrome using Selenium I am getting an error as:
File "C:Program Files (x86)Pythonlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:Program Files (x86)Pythonlibsite-packagesseleniumwebdriver
emoteerrorhandler.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
我该如何解决这个错误?
How can I fix this error?
这个错误信息...
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 无法使用指定的 用户数据目录 启动新的 Chrome 浏览器 会话,因为它已经正在使用中.
...implies that the ChromeDriver was unable to initiate the new Chrome Browser session using the specified user data directory as it was already in use.
这个错误可以重现如下:
This error can be reproduced as follows:
代码块:
Code Block:
from selenium import webdriver
import getpass
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument(r"--user-data-dir=C:Users{}AppDataLocalGoogleChromeUser Data".format(getpass.getuser()))
driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
driver.get("https://www.google.com/")
完成相关回溯:
Complete relevant traceback:
[12148:21412:0204/035557.731:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[12148:21412:0204/035557.731:ERROR:cache_util.cc(141)] Unable to move cache folder C:UsersSoma BhattacharjeeAppDataLocalGoogleChromeUser DataShaderCacheGPUCache to C:UsersSoma BhattacharjeeAppDataLocalGoogleChromeUser DataShaderCacheold_GPUCache_000
[12148:21412:0204/035557.731:ERROR:disk_cache.cc(178)] Unable to create cache
[12148:21412:0204/035557.731:ERROR:shader_disk_cache.cc(605)] Shader Cache Creation failed: -2
Opening in existing browser session.
Traceback (most recent call last):
File "C:UsersSoma BhattacharjeeDesktopDebanjanPyProgramsyandex_ru.py", line 18, in <module>
driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
File "C:Pythonlibsite-packagesseleniumwebdriverchromewebdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:Pythonlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:Pythonlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:Pythonlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:Pythonlibsite-packagesseleniumwebdriver
emoteerrorhandler.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
错误堆栈跟踪清楚地抱怨 访问被拒绝,因为程序无法将缓存文件夹 ..ShaderCacheGPUCache 移动到 ..ShaderCacheold_GPUCache_000.因此 cache 创建失败,随后 Shader Cache Creation 创建失败.虽然这些问题会引发 InvalidArgumentException,但可以在现有 Chrome 浏览器会话中强制打开一个新窗口.
The error stack trace clearly complains of Access is denied as the program was unable to move the cache folder ..ShaderCacheGPUCache to ..ShaderCacheold_GPUCache_000. hence the creation of cache failed and subsequently creation of Shader Cache Creation failed. Though these issues raises the InvalidArgumentException but forcefully able to open a new window within the existing Chrome Browser Session.
虽然抛出了错误,但新的 Chrome 窗口仍会启动,但仍与已打开的 Chrome 会话连接,但新窗口无法由 WebDriver 实例.因此,您会在 url 栏中看到 data:,.
Though the error is thrown, still the new Chrome window gets initiated but remains attached with the already opened Chrome session but the new window can't be controlled by the WebDriver instance. Hence you see data:, in the url bar.
你需要注意几件事:
user-data-dir 作为用户数据,因为它仍然被您手动启动的其他 Chrome 进程锁定.user-data-dir as the User Data as it remains locked by the other Chrome process you have initiated manually.
这篇关于InvalidArgumentException:消息:无效参数:用户数据目录已在使用错误使用 --user-data-dir 使用 Selenium 启动 Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何制作一个在 Python 中提供角色的不和谐机器人How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
Discord 机器人没有响应命令Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
你能得到“关于我"吗?Discord 机器人的功能?Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
message.channel.id Discord PYmessage.channel.id Discord PY(message.channel.id Discord PY)
如何在 heroku 上托管我的 discord.py 机器人?How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
discord.py - 自动更改角色颜色discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)