selenium chrome python“InvalidArgumentException”为userdatadir argumen指定一个唯一的值

2024-10-01 07:29:50 发布

您现在位置:Python中文网/ 问答频道 /正文

Leo's question on 8/16/2019被标记为重复,但不是!我也明白了

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

我尝试过各种形式的选项和chrome峎选项,没有改变。我尝试了指定usedatadir和不指定usedatadir,然后只显示一个通用概要文件。在

DebanjanB报告

This question already has an answer here:

How to open a Chrome Profile through Python

How to open a Chrome Profile through --user-data-dir argument of Selenium

How to use Chrome Profile in Selenium Webdriver Python 3

但是,这些只显示了如何使用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: Message: chrome not reachable


Tags: todatauseseleniumdirchromeprofileargument