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

Python Selenium自动化测试中如何禁用Chrome提示弹窗?

解决Chrome 125版本自动化测试弹窗干扰问题

针对Chrome 125更新后出现的菜单弹窗干扰测试问题,结合你的Headful模式运行场景,可通过以下调整解决:

1. 添加125版本专属禁用参数

Chrome 125新增了「新功能提示」类弹窗,常规参数已无法覆盖,需补充以下针对性参数:

  • --disable-features=ChromeWhatsNewUI:直接禁用Chrome新功能提示UI,这是本次弹窗的核心根源
  • --disable-features=NotificationPromo:禁用通知推广类弹窗
  • --no-default-browser-check:跳过默认浏览器检查弹窗
  • --user-data-dir=<固定路径>:指定固定用户数据目录,避免每次测试初始化全新配置触发首次运行提示(路径需根据系统调整,确保有读写权限)

2. 修改后的初始化代码

将上述参数整合到你的setUpClass方法中,调整后的Headful模式代码如下:

else:
    chrome_options = Options()
    # 新增125版本弹窗禁用参数
    chrome_options.add_argument('--disable-features=ChromeWhatsNewUI,NotificationPromo')
    chrome_options.add_argument('--no-default-browser-check')
    # 指定固定用户数据目录,替换为你本地的路径
    chrome_options.add_argument('--user-data-dir=C:/temp/chrome_test_profile')  # Windows示例
    # chrome_options.add_argument('--user-data-dir=/tmp/chrome_test_profile')  # Linux/macOS示例
    # 保留原有有效参数
    chrome_options.add_argument('--disable-first-run-ui')
    chrome_options.add_argument('--no-first-run')
    chrome_options.add_argument('--disable-extensions')
    chrome_options.add_argument('--enable-logging')
    chrome_options.add_argument('--disable-popup-blocking')
    chrome_options.add_argument('--disable-notifications')
    chrome_options.add_argument('--disable-infobars')
    chrome_options.add_argument('--disable-blink-features=AutomationControlled')
    cls.selenium = webdriver.Chrome(service=chrome_service, options=chrome_options)
    cls.selenium.maximize_window()
    print("Running in headful mode")

3. 错误日志处理

你遇到的[13860:24408:0604/071320.491:ERROR:interface_endpoint_client.cc(722)]错误,本质是弹窗渲染阻塞了页面交互,解决弹窗后该错误会自动消失。如果仍存在,可临时添加--disable-gpu参数(针对Windows系统GPU渲染兼容性问题)。

4. 额外验证

  • 确保ChromeDriver与Chrome版本完全一致:虽然当前版本属于兼容范围,但重新下载与Chrome 125.0.6422.142完全匹配的ChromeDriver,可避免隐性兼容问题
  • 首次运行前清理指定的用户数据目录:避免残留旧配置影响测试

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 21:25:10