Reputation: 2218
I am trying to find out how to collect just the li
child nodes inside a ul
element. I can't seem to figure out how to limit watir
to just the direct li
child nodes, and not the ones further down in the document.
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
Is there an option to watir that says only do the first level?
Upvotes: 2
Views: 2571
Reputation: 2218
This is what I came up with:
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
Upvotes: 4