I'm trying to chain find methods in Capybara and not having much luck. I would expect the second find to only look for text in the output of the first find. However, the second find searches the entire document.
element = page_foo.find('.bar')
element.find('div', :text => "name")
=> All divs with the text "name" on the page.
A solution using xpath was described here:
capybara - Find with xPath is leaving the within scope
However, I am not too familiar with xpath and hope to find a way to work around it.
Additional details:
HTML:
<div data-id="tabMeListProducts">
<div class=" title">My BMW 5-SERIES GRAN TURISMO.</div>
</div>
<div data-id="tabMeListPosts">
<div class="name">My BMW 5-SERIES GRAN TURISMO.</div>
</div>
RSPEC:
element = page_foo.find('[data-id="tabMeListProducts"]')
=>#<Capybara::Element tag="div">
element.find('div', :text => "My BMW 5-SERIES GRAN TURISMO.")
=>Capybara::Ambiguous: Ambiguous match, found 2 elements matching css "div" with text "My BMW 5-SERIES GRAN TURISMO."
As you can see from the example above the second find's scope is the entire page and is not contained within the element passed in by the initial find.
I would expect the find to only look within the div contained in the variable "element".