1

Leo 在 2019 年 8 月 16 日的问题被标记为重复,但不是!我也得到错误

selenium.common.exceptions.InvalidArgumentException:消息:无效参数:用户数据目录已在使用中,请为 --user-data-dir 参数指定唯一值,或者不要使用 --user-data-dir

我尝试了各种形式的选项和 chrome_options,没有任何变化。我尝试了使用和不指定 use-data-dir,然后它只会显示一个通用配置文件。

DebanjanB报道

这个问题在这里已经有了答案:

如何通过 Python 打开 Chrome 配置文件

如何通过 Selenium 的 --user-data-dir 参数打开 Chrome 配置文件

如何在 Selenium Webdriver Python 3 中使用 Chrome 配置文件

但是,这些仅显示了如何使用 selenium,我很确定 Leo 和我已经在代码中编写了它,但仍然会出现此错误。帮助!

这是代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

CrOptions = Options()
ProfilePath = "C:\\Users\\name\\AppData\\Local\\Google\\Chrome\\User Data\\"
CrOptions.add_argument("user-data-dir=" + ProfilePath)
ProfileName = "Profile 3"
CrOptions.add_argument("profile-directory=" + ProfileName)
browser = webdriver.Chrome(options=CrOptions)

browser.get("HTTP://msftconnectiontest.com/redirect")

它在 Chrome 中打开了正确的配置文件,但同时给出了 InvalidArgumentException 并且 get 命令返回:

selenium.common.exceptions.WebDriverException:消息:无法访问 chrome

4

0 回答 0