在 Watir 中查找具有特定类的 div 列表 [英] Finding a list of divs with a specific class in Watir
问题描述
页面上有 n 个类名相同的 div.
<div class="errors">foo 无效
我们想要做的是检查并查看是否有任何带有错误"类的 div 显示消息Foo 无效".
我们可以做到@browser.div(:class => '错误', :index => 2)
但这并不包括消息位于第一个或第 n 个 div 中的情况.
如果我们可以将所有匹配的 div 作为数组取回,将其展平,然后执行断言,那该多好.
或者获取匹配的 div 数量,以便我们可以迭代它们.
我们正在使用 Watir 1.9.2
如果您升级到 Watir 2.0 或者如果您使用 watir-webdriver gem,这将返回所有具有类 errors
和文本的 div(确切地说)Foo 无效
(如果这是您想要做的):
browser.divs(:class => "errors", :text => "Foo is invalid")
We have n-number of divs on the page with the same class name.
<div class="errors">
</div>
<div class="errors">
Foo is invalid
</div>
What we'd like to do is to check and see if any of the divs with the "error" class on them have the message "Foo is invalid".
We can do this @browser.div(:class => 'errors', :index => 2)
But that doesn't cover the case where the message is in the first or n-th div.
What would be great is if we can get all the matching divs back as an array, flatten it out, and then do our assertions.
Or perhaps get back the number of divs that match so that we can iterate over them.
We are on Watir 1.9.2
If you upgrade to Watir 2.0 or if you use watir-webdriver gem, this would return all divs that have class errors
and text (exactly) Foo is invalid
(if that is what you want to do):
browser.divs(:class => "errors", :text => "Foo is invalid")
这篇关于在 Watir 中查找具有特定类的 div 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!