首页 > 解决方案 > Chrome 不加载配置文件

问题描述

由于某种原因,程序不加载配置文件。配置文件的位置很好。

  options = webdriver.ChromeOptions() 
  options.add_argument("user-data-dir=C:\\Users\\Aron\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
  capabilities = DesiredCapabilities.CHROME.copy()
  chromedriver = 'C:\\test\\chromedriver.exe'
  # Opening the browser
  driver = webdriver.Chrome(executable_path = chromedriver, chrome_options=options, desired_capabilities=capabilities)

标签: pythonseleniumautomation

解决方案


两步:

1 - 当为配置文件使用空文件夹时,Chrome 会在该文件夹中创建一个新配置文件。如果它创建了配置文件,您可以假设它下次也会加载它。

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\test\Profile 2")

chromedriver = r'C:\test\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)

创建的文件夹

2 - 但要确保您可以使用 chrome://version/ 在 Chrome 中显示使用的配置文件。

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\test\Profile 2")

chromedriver = r'C:\test\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)

driver.get('chrome://version/')

input('Enter')

实际简介


推荐阅读