如何用水豚验证表是否为空?
我已经尝试了所有这些命令,但没有一个起作用。我什至使用了 StackOverflow 的一些提示,但我还不满意。 我已经尝试了所有这些命令,但没有一个起作用。我什至使用了 StackOverflow 的一些提示,但我还不满意。 我已经尝试了所有这些命令,但没有一个起作用。我什至使用了 StackOverflow 的一些提示,但我还不满意。
expect(find('.tvGrid').has_no_content?).to be true
expect(find('.tvGrid')).to have_no_content
expect(find('.tvGrid > tbody', visible: false)).not_to have_css('td')
expect(find('.tvGrid > tbody')).to have_no_content
<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>
I have tried all these commands but none works. I even used some tips from StackOverflow but I wasn't happy yet..
I have tried all these commands but none works. I even used some tips from StackOverflow but I wasn't happy yet..
I have tried all these commands but none works. I even used some tips from StackOverflow but I wasn't happy yet..
expect(find('.tvGrid').has_no_content?).to be true
expect(find('.tvGrid')).to have_no_content
expect(find('.tvGrid > tbody', visible: false)).not_to have_css('td')
expect(find('.tvGrid > tbody')).to have_no_content
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的关键是告诉Capybara期望没有内容的
td
元素。您可以使用text
选项的事实可以是REGEXP,以检查这将使Capybara确保与
.tvgrid TD
选择器与1个或更多元素相匹配。文本内容的字符,并将其重试甘蓝帕拉.default_max_wait_time秒,以说明动态页面。您可以根据需要调整REGEXP,以允许任何可接受的内容。The key here is tell Capybara to expect no
td
elements with contents. You can use the fact thetext
option can be a Regexp here to check for thatThis will make Capybara ensure there are no elements matching the
.tvGrid td
selector with 1 or more characters of text content, and will retry that for up to Capybara.default_max_wait_time seconds to account for dynamic pages. You can adjust the Regexp as necessary to allow any acceptable contents.重点是您可以检查 td 节点内没有文本。有很多方法可以做到这一点,
例如
or
or
.blank?
和.present?
是 ActiveSupport 方法。在 vanilla Ruby 中,您可以使用.strip.empty?
代替这些方法The point is that you can check that there is no text inside
td
nodes. There are many ways to do itAs example
or
or
.blank?
and.present?
are ActiveSupport methods. In vanilla Ruby you can use.strip.empty?
instead of these methods