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

如何在Ruby Selenium(WATIR)中设置浏览器版本

在Ruby Selenium和WATIR中指定Chrome浏览器版本的实现方法

Ruby Selenium 实现

通过Selenium::WebDriver::Chrome::Options对象设置browser_version属性,即可让Selenium自动下载并使用指定版本的Chrome。代码示例如下:

require 'selenium-webdriver'

# 创建Chrome选项对象并指定版本
options = Selenium::WebDriver::Chrome::Options.new
options.browser_version = '116'

# 初始化驱动时传入选项
driver = Selenium::WebDriver.for :chrome, options: options

WATIR 实现

WATIR基于Selenium开发,因此可以复用Selenium的Chrome选项配置,再传递给WATIR的浏览器实例:

require 'watir'

# 先创建Selenium的Chrome选项并指定版本
selenium_options = Selenium::WebDriver::Chrome::Options.new
selenium_options.browser_version = '116'

# 初始化WATIR浏览器时传入该选项
browser = Watir::Browser.new :chrome, options: selenium_options

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 20:54:50