【发布时间】:2022-12-24 20:19:51
【问题描述】:
我希望 Selenium 打开并控制我现有的名为 Selenium 的 Chrome 配置文件之一.我尝试了不同的解决方案,但都没有用。
资料名称:Selenium
配置文件目录:Profile 5
1-首先我试过:
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 控制的 Chrome 窗口中。另外,我的脚本因错误而崩溃:selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument
2-然后我尝试克隆配置文件目录并像这样引用它:
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/path_where_I_put_the_directory')
options.add_argument('profile-directory=Profile 5')
这一次,它没有给我任何崩溃,但这会打开一个 Chrome 配置文件,它就像我的 Selenium 配置文件的克隆,并且它没有连接到我的 Google 帐户,这与真实帐户不同。
有图像,real profile VS the clone:
【问题讨论】:
-
尝试使用“--user-data-dir=”(包括开头的破折号)
-
@LukeHamilton 不,不幸的是,那行不通。
标签: selenium selenium-webdriver selenium-chromedriver