我正在尝试了解如何在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
是否有选项可以说只做第一级?
答案 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