【问题标题】:Can't run Chrome browser with custom profile selenium无法使用自定义配置文件 selenium 运行 Chrome 浏览器
【发布时间】:2017-04-13 08:18:13
【问题描述】:

我正在尝试使用包含必要 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);

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

【问题讨论】:

  • 您能否详细说明您是如何尝试访问新的 Chrome 配置文件的?
  • 我解决了我的问题。谢谢。
  • @PanamaBoy 出了什么问题?
  • 您能分享一下您是如何解决问题的吗?

标签: selenium testing selenium-chromedriver


【解决方案1】:

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

确保将user-data-dir 更改为Chrome User Data 目录。不用担心空间。不要尝试在参数值中加上引号或转义空格。

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")

Keep this in mind 运行代码时。 (基本上,在使用自定义 Chrome 配置文件运行 selenium 之前关闭所有打开的 Chrome 实例)

【讨论】:

    猜你喜欢
    • 2012-05-08
    • 2022-08-05
    • 1970-01-01
    • 2023-01-07
    • 1970-01-01
    • 2018-06-08
    • 2021-05-16
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多