Rails Watir Webdriver - select 选项无效

Rails Watir Webdriver - select option not working

我正在 Rails 中编写网络抓取工具,无法让 Watir 从 select 标签中选择 select 选项。我尝试了多种变体,但从各方面来看,这应该有效:

browser.select_list(:id, "system").select("PC")

我已经测试以确保 select 框和值都存在,我已经使用睡眠来延迟点击以允许加载所有内容,我已经使用 .when_present,我已经在 pry 中尝试过(我可以在 pry 中设置和取消设置复选框并实时查看效果,而不是 select 框的情况)并且我没有想法。没有错误消息,它什么都不做。

完整代码如下:

require 'watir-webdriver'
require 'pry'

browser = Watir::Browser.new
browser.goto 'http://www.co-optimus.com/games.php'

browser.div(id: "system-modal").link(class: "close-reveal-modal").click

sleep 5
browser.select_list(:id, "system").when_present.select("PC")

sleep 1
browser.checkbox(id: "couch").when_present.set

sleep 2
browser.link(text: "Find Games").when_present.click

首先,watir 已弃用 watir-webdriver。如果您使用 gem "watir", "~> 6.0.0",则不需要包含 #when_present(或睡眠)。

这对我有用(现在默认使用 Chrome)

require 'watir'

browser = Watir::Browser.new
browser.goto 'http://www.co-optimus.com/games.php'
browser.div(id: "system-modal").a.click
browser.select_list(id: "system").select("PC")
browser.checkbox(id: "couch").set
browser.button(text: "Find Games").click

在我的屏幕上使用 browser = Watir::Browser.new :firefox 实际上会导致点击 "Find Games" 出现问题(我需要使用 watir-scroll 来解决 javascript 覆盖问题) , 但与 select 列表一起工作就好了。 (这也适用于 Firefox 50)。

使用带有 geckodriver 的早期版本的 Firefox 的 Select 列表存在一些问题,因此您可能需要使用 Chrome 或更新您的 Firefox 版本。