You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium ChromeDriver如何打开指定Chrome配置文件

问题:使用Selenium控制已有Chrome配置文件失败

目标:用Selenium打开并控制名为Selenium的Chrome配置文件(对应目录为Profile 5),但两次尝试均未达到预期效果:

第一次尝试

使用以下代码:

options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/raphg/AppData/Local/Google/Chrome/User Data')
options.add_argument('profile-directory=Profile 5') 

结果:打开了正确的Chrome配置文件,但窗口不受Selenium控制,同时脚本报错:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument

第二次尝试

克隆配置文件目录后,使用以下代码引用:

options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/path_where_I_put_the_directory') 
options.add_argument('profile-directory=Profile 5')

结果:无报错,但打开的是Selenium配置文件的克隆版本,未关联谷歌账号,与原配置文件存在差异(原配置文件已登录谷歌账号,克隆版本未登录)


内容的提问来源于stack exchange,提问作者Raphaël Goisque

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 01:15:11