获取watir-webdriver中的子节点集合

时间:2013-06-07 23:19:34

标签: ruby watir watir-webdriver

我正在尝试了解如何在li元素中收集 ul个子节点。我似乎无法弄清楚如何将watir限制为直接li子节点,而不是文档中更下方的节点。

b = Watir::Browser.start "http://example.com"
section_list = b.ul(:id => 'section_list')
section_list.lis #=> this returns *all* the li elements until section_list

是否有选项可以说只做第一级?

1 个答案:

答案 0 :(得分:4)

这就是我提出的:

Then(/^the element with id of "(.*?)" should have (\d+) children$/) do |id, n|
  el = @browser.element(:id => id)
  el.elements(:xpath, "./*").count.should eql(n.to_i)
end