我看过有关此问题的几篇文章,但不幸的是,没有一篇文章可以帮助解决我的问题
这是我必须使用刚刚创建的“Selenium”特定配置文件打开Chrome的代码。我已为Chrome 83下载了最新版本的ChromeDriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--user-data-dir=C:\\Users\\Ryan\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\Users\Ryan\Workspace\Tools\Selenium\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com")
最佳答案
我能够复制此问题。我无法解释为什么会发生这种情况,但是可以通过添加一个附加参数来解决。我将--user-data-dir更改为指向配置文件主页User Data。然后,我使用--profile_directory指定了想要的配置文件。
这是我在计算机上运行的内容。
ch_options = Options()
ch_options.add_argument("--user-data-dir=C:/Users/jeffg/AppData/Local/Google/Chrome/User Data")
ch_options.add_argument("--profile-directory=Profile 1") #This is the additional argument
driver = webdriver.Chrome(executable_path=chrome_path, chrome_options=ch_options)
因此,在您的示例中,它想要这样的内容:
options = Options()
options.add_argument("--user-data-dir=C:\\Users\\Ryan\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("--profile-directory=Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\Users\Ryan\Workspace\Tools\Selenium\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com")
希望这可以帮助。
关于python - Selenium 在Chrome中以新用户身份不断开放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62239530/