Selenium调用Chrome复用已有会话致自动化失败求助
Selenium + ChromeDriver Web自动化脚本失效问题
近期团队发现基于Selenium与ChromeDriver的Web自动化脚本失效,使用Python Selenium调用Chrome浏览器实例时触发如下报错:
Opening in existing browser session. Traceback (most recent call last): File "c:\Programs\DMT Web Apps\DMT\github\taf-rapid-layeredapps-automation-robot\rapidrtcautomation\tests\test.py", line 7, in <module> driver = webdriver.Chrome(chrome_options=options) File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__ super().__init__( File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 105, in __init__ super().__init__( File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 442, in execute self.error_handler.check_response(response) File "C:\Users\William.Tan\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally. (chrome not reachable) (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.)
经观察,Chrome未启动新浏览器窗口,而是在已有窗口中打开标签页,导致ChromeDriver无法建立连接。以下为调试用简化代码:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--remote-allow-origins=*') options.add_argument('--remote-debugging-port=9222') driver = webdriver.Chrome(chrome_options=options) driver.get('https://www.google.com')
目前已尝试以下操作但问题仍未解决:
- 关闭防火墙
- 更新Chrome浏览器至最新版本
- 添加上述启动参数
该故障仅出现在Chrome浏览器上,Edge与Firefox均能正常运行自动化脚本,恳请协助排查原因。
内容的提问来源于stack exchange,提问作者wmtan01
相关产品推荐
相关产品推荐

