【发布时间】:2016-12-19 19:57:41
【问题描述】:
我创建了这个方法来循环访问网站中某个 div 中的链接。我的方法是收集链接,将它们插入到一个数组中,然后单击其中的每一个。
require 'watir-webdriver'
require 'watir-webdriver/wait'
site = Watir::Browser.new :chrome
url = "http://www.cnn.com/"
site.goto url
box = Array.new
container = site.div(class: "column zn__column--idx-1")
wanted_links = container.links
box << wanted_links
wanted_links.each do |link|
link.click
site.goto url
site.div(id: "nav__plain-header").wait_until_present
end
site.close
到目前为止,我似乎只能点击第一个链接,然后我收到一条错误消息,说明:
unable to locate element, using {:element=>#<Selenium::WebDriver::Element:0x634e0a5400fdfade id="0.06177683611003881-3">} (Watir::Exception::UnknownObjectException)
我对红宝石很陌生。我很感激任何帮助。谢谢。
【问题讨论】:
标签: ruby automation watir