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

Watir连接Chrome浏览器报错求助,需适配Edge浏览器

解决Watir连接Chrome/Edge调试模式的报错问题

Chrome 解决方案

使用Selenium官方的Chrome::Options类配置调试地址,这是Watir 7+(基于Selenium 4)要求的W3C标准写法,替代直接传递哈希参数的旧方式:

require 'watir'

# 创建Chrome选项对象并设置调试地址
chrome_options = Selenium::WebDriver::Chrome::Options.new
chrome_options.debugger_address = '127.0.0.1:8181'

# 初始化浏览器
browser = Watir::Browser.new :chrome, options: chrome_options
browser.goto 'www.google.com'
browser.text_field(name: 'q').set 'Raja'

错误原因说明

  1. 旧写法中直接传递'chromeOptions'键已被废弃:Watir 7不再支持这种非标准参数传递方式,所有浏览器选项必须通过Selenium对应的Options类配置。
  2. 驼峰式debuggerAddress不兼容W3C标准:Selenium 4要求使用下划线命名的属性debugger_address,直接传哈希会被判定为非合规选项触发报错。

Edge 适配方案

Edge基于Chromium内核,配置逻辑和Chrome一致,只需替换为Edge::Options类:

require 'watir'

edge_options = Selenium::WebDriver::Edge::Options.new
edge_options.debugger_address = '127.0.0.1:8181'

browser = Watir::Browser.new :edge, options: edge_options
# 后续操作示例
browser.goto 'www.bing.com'
browser.text_field(name: 'q').set 'Rajagopalan'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 14:09:51