Reputation: 358
I want to do something like this:
within '.Collection .Thing:first-child' do
page.must_have_content 'lorem ipsum'
end
Where .Thing
is just one of many other Things inside Collection. I tried the code above but it says it's ambiguous. Is there a way to resolve the ambiguity?
Upvotes: 0
Views: 648
Reputation: 49910
If you really just want the first matching element on the page you can do
within first('.Collection .Thing:first-child', minimum: 1) do
page.must_have_content 'lorem ipsum'
end
the minimum: 1 option isn't necessarily needed if the page is already fully loaded, however it will make Capybara wait for at least one matching element to show on the page if the page isn't yet fully loaded (or the list is filled via ajax, etc). Without it #first would normally return immediately with nil if no matching elements were on the page
Upvotes: 3