2015-10-08 60 views
2

在我的应用程序中,我已检查任何一个复选框并单击保存按钮。我与表用于如下选择的选项,但它不工作:选中表格中的复选框

# with in table, set 
within_table('countryTable') do 
    find(:xpath, "//tbody/tr/td[1]/checkbox").set(true) 
end 

click_button('Save') 

,但它不工作.....

这个老板

选择国家
           <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> 

回答

2

您可以通过我到达复选框d,css或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() 

,如果你想使用within_table其范围缩小:

within_table(find(:id, "table_id")) do 
    find(:id, "id_of_option").click() 
end 
+0

谢谢你需要帮助。如果我卡在我的代码中,我会保持发布。 –

+0

无论出于何种原因,检查方法和您的示例都不起作用。我不知道为什么,因为唯一的ID确实存在,并且没有重复。 – chaostheory

+0

@chaostheory你运行Ramesh案件,并没有通过?任何错误请给它? –