列表仅填充了辣椒的记录

发布于 2025-01-21 13:35:01 字数 2461 浏览 2 评论 0原文

朋友帮助我提供了一个解决方案,该解决方案可以验证列表中是否存在[活动/非活动]记录。当我使用PP Capybara列出记录时,还会返回空白行。如何无视空记录?

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr > td:nth-child(5)').each do |td|
    puts td.text
  end
end
<table width="100%" class="tvGrid">
  <tbody>
  <tr>
    <th colspan="1" class="tvHeader">Id</th>
    <th colspan="1" class="tvHeader">Code</th>
    <th colspan="1" class="tvHeader">Description</th>
    <th colspan="1" class="tvHeader">Operational Center</th>
    <th colspan="1" class="tvHeader">Status</th>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="tvRowEmpty">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
   </tr>
  </tbody>
</table>

Friends helped me with a solution that validates if there are [active/inactive] records in the list. When I list the records using pp capybara also returns blank lines. How do I disregard empty records?

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr > td:nth-child(5)').each do |td|
    puts td.text
  end
end
<table width="100%" class="tvGrid">
  <tbody>
  <tr>
    <th colspan="1" class="tvHeader">Id</th>
    <th colspan="1" class="tvHeader">Code</th>
    <th colspan="1" class="tvHeader">Description</th>
    <th colspan="1" class="tvHeader">Operational Center</th>
    <th colspan="1" class="tvHeader">Status</th>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr class="tvRowEmpty">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
   </tr>
  </tbody>
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后知后觉 2025-01-28 13:35:01

您是否在询问如何从搜索结果中删除类TVRowEmpty的行?如果是这样,您可以使用:不是在查找器中的操作员:

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr:not(.tvRowEmpty) > td:nth-child(5)').each do |td|
    puts td.text
  end
end

如果要排除仅包含&amp; nbsp;的任何td您可以将以下查找器与以下等级使用,该正则滤波器仅过滤包含空格字符的标签:

page.all('.tvGrid tr > td:nth-child(5)', text: /[\s]^*/).each 

Are you asking how to remove the rows with the class tvRowEmpty from your search results? If so, you can use the :not operator in your finder:

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr:not(.tvRowEmpty) > td:nth-child(5)').each do |td|
    puts td.text
  end
end

If you want to exclude any td that just contains   you could use the following finder with a regex that filters tags containing only whitespace characters:

page.all('.tvGrid tr > td:nth-child(5)', text: /[\s]^*/).each 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文