通过属性获取元素
我会很短。
据我所知,watir 库提供了两种获取 html 元素的方法。
几乎对于每个元素(div、button、table、li 等)watir 都提供了两种方法:
.一种是“单一”方法,仅获取一个特定元素。例如:
watir_instance.div(:id,'my_div_id')
watir_instance.link(:href,'my_link_href')
watir_instance.button(:class =>'my_button_class', :index => 4)
这些方法将仅检索单个元素。没关系...
。第二种是“复数”方法,它将检索 watir 实例的所有元素
watir_instance.divs
watir_instance.links
watir_instance.buttons
,但据我所知,watir 没有提供一种在给定条件的情况下获取多个元素的方法。
例如...如果我想刷新所有带有 id:my_link_id 的链接,那么做这样的事情会很容易:
watir_instance.divs(:id, 'my_link_id').each do |link|
link.flash
end
使用 hpricot 这个任务非常简单...但是如果你的目标不是解析我就不能找到一个满足我要求的 Watir 方法。
希望你能理解我...
干杯,胡安!
i will be short.
As far as i know watir library provides two methods for getting html elements.
Almost for each element (div, button, table, li, etc) watir provides two methods:
. One is the 'singular' method which gets only one specific element. For example:
watir_instance.div(:id,'my_div_id')
watir_instance.link(:href,'my_link_href')
watir_instance.button(:class =>'my_button_class', :index => 4)
These methods will only retrieve A SINGLE ELEMENT. Thats ok...
. The second is the 'plural' method that will retrieve ALL the elements of the watir instance
watir_instance.divs
watir_instance.links
watir_instance.buttons
But as far as i know watir doesn't provide a method to get more than one element giving certain conditions.
For example... If i want to flash all the links with id:my_link_id it would be very easy to do something like this:
watir_instance.divs(:id, 'my_link_id').each do |link|
link.flash
end
With hpricot this task is very easy... but if your aim is not to parse i couldn't find a Watir Method that does what i want.
Hope you can understand me...
Cheers, Juan!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Juan,
您的脚本有几个问题:
watir_instance.divs
。 将参数传递给divs
方法的应该是watir_instance.links
watir_instance.divs(:id, 'my_link_id')
。它应该只是watir_instance.divs
你的例子也很奇怪:
据我所知,id 在页面上应该是唯一的。
因此,这里有不同的示例:
1) 闪现此页面上的所有链接:
2) 闪现此页面上 URL 中有
问题
的所有链接(奖励:滚动页面,以便闪现的链接可见) ):Juan,
your script has several problems:
watir_instance.divs
. It should bewatir_instance.links
divs
method:watir_instance.divs(:id, 'my_link_id')
. It should be justwatir_instance.divs
Your example is also strange:
As far as I know, id should be unique at the page.
So, here are different examples:
1) Flash all links on this page:
2) Flash all links on this page that have
questions
in URL (bonus: scroll the page so the link that is flashed is visible):