rspec - Chaining Finds in Capybara? -


i'm trying chain find methods in capybara , not having luck. expect second find text in output of first find. however, second find searches entire document.

element = page_foo.find('.bar') element.find('div', :text => "name")  => divs text "name" on page. 

a solution using xpath described here:

capybara - find xpath leaving within scope

however, not familiar xpath , hope find way 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" text "my bmw 5-series gran turismo." 

as can see example above second find's scope entire page , not contained within element passed in initial find.

i expect find within div contained in variable "element".

i remember nested find calls working in past versions of cucumber or capybara. however, things change every version. regardless, example more handled nested css expressions instead of relying on multiple finds.

for example:

page_foo.find('[data-id="tabmelistproducts"] .title') or

page_foo.find('[data-id="tabmelistproducts"] div', :text => "my bmw 5-series gran turismo.")

if there multiple occurrences, use all instead of find , run own ruby checking logic on collection.

also, within works alternative (no need call find 1 response mentioned, can add css directly next it):

within '[data-id="tabmelistproducts"]' element.find('div', :text => "my bmw 5-series gran turismo.") end

lastly, if insist on using nested find calls, try doing them on same ruby line mentioned capybara documentation: page.find('#foo').find('.bar') it's possible it's lazy fetched, activates @ end of ruby line (through meta-programming checks line number).

if else fails, open github issue: http://www.rubydoc.info/github/jnicklas/capybara/capybara/node/finders#find-instance_method

you'd surprised how fast people respond you, have feeling 1 of solutions above work.

good luck! understand can frustrating issue, i'm sure got it!


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -