簡體   English   中英

Selenium 在 Chrome 中不斷作為新用戶打開

[英]Selenium keeps opening as new User in Chrome

我已經查看了有關此問題的幾篇帖子,但不幸的是,沒有一個可以幫助解決我的問題

這是我必須使用剛剛創建的“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")

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM