首页 > 解决方案 > python webdriver_manager chrome 自定义配置文件

问题描述

如何使 webdriver_manager.chrome 使用自定义 chrome 用户配置文件?

我知道对于 selenium webdriver,我可以这样指定:

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=f'{script_path}\\chromedriver.exe', options=options)

但是因为我想让 chromedriver 自己安装正确的版本(因为我把我的程序卖给了非 python 用户)我正在使用 webdriver_manager 模块,它看起来像这样:

driver = webdriver.Chrome(ChromeDriverManager().install())

有什么方法可以加载自定义配置文件,以便在使用 webdriver_manager 时将我在网站上的登录数据保存在我的配置文件中?

标签: pythonseleniumwebdriverselenium-chromedriverwebdriver-manager

解决方案


您可以使用以下解决方案同时使用webdriver_manager.chrome自定义 chrome 用户配置文件:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
driver.get('https://www.google.com/')

推荐阅读