无法使用自定义配置文件硒运行 Chrome 浏览器

Pan*_*Boy 2 testing selenium selenium-chromedriver

我正在尝试使用包含必要 cookie 的自定义配置文件在 chrome 浏览器中启动 selenium 测试。我使用 Chrome 57 和 chromedriver 2.29 我的代码是:

ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches", "--disable-extensions");
options.addArguments("user-data-dir=/Users/tester/Desktop/ChromeProf/QAChromeProfile");
options.addArguments("--ignore-certificate-errors","disable-infobars","enable-automation","--window-size=375,667");
WebDriver driver = new ChromeDriver(options);
Run Code Online (Sandbox Code Playgroud)

它工作正常,但不要使用我的 chrome 配置文件。帮帮我,请...)

小智 5

不要在user-data-dir参数中包含配置文件目录。将user-data-dir选项与默认配置之外的任何配置文件一起使用时,我还必须使用该profile-dir参数。

确保您更改user-data-dirChrome 用户数据目录。不用担心空格。不要尝试在参数值中放置引号或转义空格。

Profile 1

from selenium.webdriver import Chrome, ChromeOptions

options = ChromeOptions()
options.add_argument("user-data-dir=C:/Users/<username>/AppData/Local/Google/Chrome/User Data")
options.add_argument("profile-directory=Profile 1")

driver = Chrome(executable_path=r'C:/path/to/chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com")
Run Code Online (Sandbox Code Playgroud)

运行代码时请记住这一点。(基本上,在使用自定义 Chrome 配置文件运行 selenium 之前关闭所有打开的 Chrome 实例)