Chrome 无法使用用户配置文件运行selenium

lymgl2op  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(217)

Selenium一直在工作,直到我尝试添加一个Chrome配置文件,现在我不断得到一个错误

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# chrome driver path to file downloade
service = Service(executable_path='./chromedriver.exe')

options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data")
options.add_argument(r'--profile-directory=Profile 3') 
browser=webdriver.Chrome(service=service, options=options)

browser.get('https://google.com')

输出:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
        GetHandleVerifier [0x00007FF69CA27892+54818]
        (No symbol) [0x00007FF69C996AC2]
        (No symbol) [0x00007FF69C84DA3B]
        (No symbol) [0x00007FF69C87C202]
        (No symbol) [0x00007FF69C87802E]
        (No symbol) [0x00007FF69C8B67FB]
        (No symbol) [0x00007FF69C8AE883]
        (No symbol) [0x00007FF69C883691]
        (No symbol) [0x00007FF69C8848D4]
        GetHandleVerifier [0x00007FF69CD8B992+3610402]
        GetHandleVerifier [0x00007FF69CDE1860+3962352]
        GetHandleVerifier [0x00007FF69CDD9D4F+3930847]
        GetHandleVerifier [0x00007FF69CAC3646+693206]
        (No symbol) [0x00007FF69C9A1628]
        (No symbol) [0x00007FF69C99D934]
        (No symbol) [0x00007FF69C99DA62]
        (No symbol) [0x00007FF69C98E113]
        BaseThreadInitThunk [0x00007FFF439B7614+20]
        RtlUserThreadStart [0x00007FFF442C26B1+33]

它打开选项卡,但随后立即失败。尝试多次更新Chrome驱动程序,它与配置文件一起工作。

jslywgbw

jslywgbw1#

在末尾添加\Profile 3,如下所示:

options.add_argument(r"--user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data\Profile 3")

相关问题