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

Ruby-Selenium环境下禁用Chromium“重新加载页面”弹窗问题求助

解决方案

  1. 修复版本兼容问题
    你当前使用的selenium-webdriver 2.53.x为老旧版本,仅适配Chromium 54及更早版本,若你本地运行的Chromium版本高于该范围,会出现大量未定义异常,包括你遇到的页面重载弹窗。可二选一处理:
  • 降级Chromium到54.x及以下版本,和现有Selenium版本匹配
  • 升级selenium-webdriver到4.x版本,同时安装对应版本的ChromeDriver匹配你当前的Chromium版本,Gemfile对应修改为:
    gem 'selenium-webdriver', '~> 4.10'
    
  1. 补充启动参数
    现有启动参数未覆盖弹窗拦截场景,在你的初始化配置中新增以下参数:
options.add_argument('--disable-notifications')
options.add_argument('--noerrdialogs')
options.add_argument('--disable-session-crashed-bubble')
options.add_argument('--disable-restore-session-state')
  1. 新增偏好配置
    在原有的prefs配置中新增两项内容,避免浏览器误判上次会话异常触发重载提示:
prefs = {
  download: {
    'prompt_for_download' => false,
    'default_directory' => 'location'
  },
  plugins: {
    'always_open_pdf_externally' => true
  },
  # 新增以下两行
  'profile.exit_type' => 'Normal',
  'profile.exited_cleanly' => true
}
  1. 启动前清理残留进程
    多次运行后残留的Chromium后台进程会导致会话异常,每次初始化Selenium前先清理残留进程:
# Windows环境执行
system('taskkill /f /im chrome.exe 2>nul')
# Linux/macOS环境执行
system('pkill -f chromium 2>/dev/null')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 20:54:09