选择元素及其父元素,以及它获得的所有字符串
Selecting elements and its parent, with all Strings that it got
我使用 Capybara 编写验收测试。我想确保我的元素在页面上可见。我如何 select 元素及其获得的所有字符串?
页面如下所示
<tr>
<td class="pl-4">ABC</td>
<td class="text">5000$</td>
<td>
<span class="spanclass">
SpanClassExample
</span>
<br>
<a class="badge badge-secondary" href="//.../">CLASS</a>
</td>
<td class="text-right">NAME1</td>
<td>NAME2</td>
<td>NAME3</td>
<td>NAME4</td>
<td>NAME5</td>
</tr>
目前我使用这个方法
page.all(".text-right", text: 'NAME1')[0].visible?
但我需要找到包含所有字符串的元素
NAME1
NAME2
NAME3
NAME4
NAME5).
还有这个元素
(span class="spanclass" SpanClassExample /span>)
我建议为该行添加一个 ID,例如:
<tr id="thing-<%= thing.id %>">
以便您以后可以做:
within("tr#thing-#{thing.id}") do
expect(page).to have_content thing.name # or whatever you want to look for
end
我使用 Capybara 编写验收测试。我想确保我的元素在页面上可见。我如何 select 元素及其获得的所有字符串?
页面如下所示
<tr>
<td class="pl-4">ABC</td>
<td class="text">5000$</td>
<td>
<span class="spanclass">
SpanClassExample
</span>
<br>
<a class="badge badge-secondary" href="//.../">CLASS</a>
</td>
<td class="text-right">NAME1</td>
<td>NAME2</td>
<td>NAME3</td>
<td>NAME4</td>
<td>NAME5</td>
</tr>
目前我使用这个方法
page.all(".text-right", text: 'NAME1')[0].visible?
但我需要找到包含所有字符串的元素
NAME1 NAME2 NAME3 NAME4 NAME5).
还有这个元素
(span class="spanclass" SpanClassExample /span>)
我建议为该行添加一个 ID,例如:
<tr id="thing-<%= thing.id %>">
以便您以后可以做:
within("tr#thing-#{thing.id}") do
expect(page).to have_content thing.name # or whatever you want to look for
end