1

在下面的 HTML 代码中,我所在的行包含 4 列:read、、create和(城市和项目两次)editdelete

我想做的是检查项目中是否选中了读取按钮。我是水豚的新手,我试过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>

在此处输入图像描述

4

4 回答 4

6

您的代码显然表明您的复选框是图像。

如果你有真正的复选框,你可以使用这些 capybara 方法来测试你的复选框是否被选中:

has_checked_fieldhas_no_check_field

于 2013-10-08T08:49:39.190 回答
1

expect(page).to have_checked_field("my_check_name")

文档链接:http ://www.rubydoc.info/github/jnicklas/capybara/Capybara%2FRSpecMatchers%3Ahave_checked_field

于 2017-07-05T22:55:03.423 回答
0

这对我有用

assert page.has_checked_field?('your_checkbox_id')
于 2016-08-29T15:36:54.967 回答
-1

您可以使用 page.should have_xpath 命令改进这一点:

page.should have_xpath('//table[@class='crudTable'][2]//td[@class='crudCol'][1]/img[@alt='Checked']')
于 2013-10-09T17:15:17.317 回答