You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome升级至127版本后Selenium脚本报错求助

解决Chrome 127版本下Selenium脚本报错问题

是的,大量用户在升级Chrome到127版本后遇到了相同问题——Chrome强制弹出的搜索引擎选择界面会阻塞Selenium自动化操作,导致脚本超时、元素定位失败或会话创建异常。

你添加--disable-search-engine-choice-screen参数的方向是正确的,但可能需要结合以下调整彻底解决问题:

1. 确保ChromeDriver与Chrome版本完全匹配

WebDriver Manager偶尔会缓存旧版本驱动,导致版本不兼容。可以手动指定对应Chrome 127的驱动版本强制安装:

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

chrome_options = Options()
# 禁用搜索引擎选择弹窗
chrome_options.add_argument("--disable-search-engine-choice-screen")
# 补充参数规避其他首次运行干扰
chrome_options.add_argument("--no-first-run")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-popup-blocking")

# 指定Chrome 127对应的驱动版本(版本号可根据实际Chrome小版本调整)
service = Service(ChromeDriverManager(driver_version="127.0.6533.88").install())

driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get('https://www.google.com')
print(driver.title)

driver.quit()

2. 针对不同报错的排查方向

如果仍报错,先明确具体错误类型:

  • SessionNotCreatedException:驱动与Chrome版本不匹配,确认Chrome版本后手动指定对应驱动版本即可。
  • TimeoutException:页面加载时仍有其他弹窗干扰,可添加chrome_options.add_argument("--disable-extensions")进一步屏蔽干扰项。
  • 元素定位失败:页面加载未完成,建议用显式等待替代固定休眠:
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver.get('https://www.google.com')
    # 等待页面标题加载完成
    WebDriverWait(driver, 10).until(EC.title_contains("Google"))
    print(driver.title)
    

内容的提问来源于stack exchange,提问作者Bekkkk23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 13:02:39