在以下HTML代码中,我的行包含4列:read
,create
,edit
和delete
(城市和项目的两次)。< / p>
我想做的是检查项目中是否选中了读取按钮。我是水豚的新手,我试过find('citites')
然后我不知道如何提及它的孩子来检查是否检查了创建。
非常感谢您的帮助。
<tr>
<th class="labelCol" scope="row">Cities</th>
<td class="dataCol col02">
<table class="crudTable">
<tbody>
<tr class="crudTable">
<td class="crudCol">
<img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" id="crudRead___01Ib0000000118kEAA" title="Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudCreate___01Ib0000000118kEAA" title="Not Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudUpdate___01Ib0000000118kEAA" title="Not Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudDelete___01Ib0000000118kEAA" title="Not Checked">
</td>
<td class="marvarCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudViewAll___01Ib0000000118kEAA" title="Not Checked">
</td>
<td class="marvarCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudModifyAll___01Ib0000000118kEAA" title="Not Checked">
</td>
</tr>
</tbody>
</table>
</td>
<th class="labelCol" scope="row">Projects</th>
<td class="dataCol">
<table class="crudTable">
<tbody>
<tr class="crudTable">
<td class="crudCol">
<img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" id="crudRead___01Ib00000001HDjEAM" title="Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" id="crudCreate___01Ib00000001HDjEAM" title="Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" id="crudUpdate___01Ib00000001HDjEAM" title="Checked">
</td>
<td class="crudCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudDelete___01Ib00000001HDjEAM" title="Not Checked">
</td>
<td class="marvarCol">
<img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudViewAll___01Ib00000001HDjEAM" title="Not Checked">
</td>
<td class="marvarCol"><img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" id="crudModifyAll___01Ib00000001HDjEAM" title="Not Checked">
</td>
</tr>
答案 0 :(得分:6)
答案 1 :(得分:1)
expect(page).to have_checked_field("my_check_name")
链接到doc:http://www.rubydoc.info/github/jnicklas/capybara/Capybara%2FRSpecMatchers%3Ahave_checked_field
答案 2 :(得分:0)
这个对我有用
assert page.has_checked_field?('your_checkbox_id')
答案 3 :(得分:-1)
您可以使用page.should have_xpath命令改进此功能:
page.should have_xpath('//table[@class='crudTable'][2]//td[@class='crudCol'][1]/img[@alt='Checked']')