Reputation: 69
In my application I have check any one of the check box and click on save button. I used with table as follows to select the option, but it doesnt work:
# with in table, set
within_table('countryTable') do
find(:xpath, "//tbody/tr/td[1]/checkbox").set(true)
end
click_button('Save')
but its not working.....
Select countries for this owner
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxAU' name='AU' value='AU' />
</td>
<td>
Australia
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCA' name='CA' value='CA' />
</td>
<td>
Canada
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxFR' name='FR' value='FR' />
</td>
<td>
France
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGG' name='GG' value='GG' />
</td>
<td>
Guernsey
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxJP' name='JP' value='JP' />
</td>
<td>
Japan
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxNZ' name='NZ' value='NZ' />
</td>
<td>
New Zealand
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxZA' name='ZA' value='ZA' />
</td>
<td>
South Africa
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCH' name='CH' value='CH' />
</td>
<td>
Switzerland
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxAE' name='AE' value='AE' />
</td>
<td>
United Arab Emirates
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGB' name='GB' value='GB' />
</td>
<td>
United Kingdom
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxUS' name='US' value='US' />
</td>
<td>
United States
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
Upvotes: 2
Views: 377
Reputation: 7401
You can reach the check box by id, css, or xpath.
# to check the FR with xpath
find(:xpath, "//input[@name='FR']").click()
# to check the FR with id
find(:id, "CheckboxFR").click()
# to check the FR with css
find(:css, "#CheckboxFR").click()
if you want to use within_table which narrow the scope:
within_table(find(:id, "table_id")) do
find(:id, "id_of_option").click()
end
Upvotes: 2