testing - Click checkbox with Nested Elements in Watir -


i'll try keep simple.

i have list of similar rows this:

enter image description here

html code:

<li ...>     <div ... >         <some elements here>     </div>     <input id="121099" class="containermultiselect" type="checkbox" value="121099" name="nodeids">     <a ...>         <div ... />         <div ... >             <h2>identified text</h2>             <h3>...</h3>         </div>     </a> </li> 

i want click checkbox text, can't use of elements, because same list, , id generated automatically. thing can differentiated h2 text. tried :

browser.h2(:text => /identified/).checkbox(:name => "nodeids").set 

and got unknownexception obvious because checkbox not nested tag.

what can in case?

thanks

the h2 , checkbox related li, common ancestor. therefore, find checkbox, can li contains h2 element. find readable approach doing using find method of element collection. find method allows make custom locators.

the code be:

parent_li = browser.lis.find |li|     li.h2(:text => 'identified text').present? end parent_li.checkbox.set 

notes:

  • browser.lis creates collection of li elements.
  • find iterates through lis , returns first element has block evaluate true - ie first li h2 specified text present.

Comments