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
相关产品推荐
相关产品推荐

