我正在尝试使用Capybara在包含特定名称的表中选择一行。不幸的是,Capybara似乎只看到了桌子上的乱语。以下是我获得的以下代码:
page.all('table tr').map { |e| e.text }
=> ["", "y y y w y", "y y w y", "y y y w y", "y y w y", "y y w y w y"]
更新:以下是它正在尝试处理的表格:
<table class="views-table cols-5">
<thead>
<tr>
<th class="views-field views-field-phpcode">Status</th>
<th class="views-field views-field-name">Name</th>
<th class="views-field views-field-field-id">ID</th>
<th class="views-field views-field-phpcode-1">Actions</th>
</tr>
</thead>
<tbody>
<tr class="odd views-row-first">
<td class="views-field views-field-phpcode">
<img title="Complete" src="..."><br>Complete
</td>
<td class="views-field views-field-name">Harvey</td>
<td class="views-field views-field-field-id">1</td>
<td class="views-field views-field-phpcode-1">
<a class="existing_submit disabled" href="...">Edit</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to reset?" href="...">Reset</a>
<div style="clear: left;"></div>
<a class="existing_submit disabled" href="...">Import</a>
<a class="existing_submit disabled" target="_blank" href="...">View</a>
<a class="existing_submit" target="_blank" href="...">Replay</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to submit the results?" href="...">Submit</a>
<a class="existing_submit" target="_blank" href="...">Print</a>
</td>
</tr>
<tr class="even">
<td class="views-field views-field-phpcode">
<img title="Complete" src="..."><br>Complete
</td>
<td class="views-field views-field-name">Lucas</td>
<td class="views-field views-field-field-id">2</td>
<td class="views-field views-field-phpcode-1">
<a class="existing_submit disabled" href="...">Edit School</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to reset?" href="...">Reset</a>
<div style="clear: left;"></div>
<a class="existing_submit disabled" href="...">Import</a>
<a class="existing_submit disabled" target="_blank" href="...">View</a>
<a class="existing_submit" target="_blank" href="...">Replay</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to submit the results?" href="...">Submit</a>
<a class="existing_submit" target="_blank" href="...">Print</a>
</td>
</tr>
<tr class="odd">
<td class="views-field views-field-phpcode">
<img title="Complete" src="..."><br>Complete
</td>
<td class="views-field views-field-name">Sarah</td>
<td class="views-field views-field-field-id">3</td>
<td class="views-field views-field-phpcode-1">
<a class="existing_submit disabled" href="...">Edit</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to reset?" href="...">Reset</a>
<div style="clear: left;"></div>
<a class="existing_submit disabled" href="...">Import</a>
<a class="existing_submit disabled" target="_blank" href="...">View</a>
<a class="existing_submit" target="_blank" href="...">Replay</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to submit the results?" href="...">Submit</a>
<a class="existing_submit" target="_blank" href="...">Print</a>
</td>
</tr>
<tr class="even">
<td class="views-field views-field-phpcode">
<img title="Complete" src="..."><br>Complete
</td>
<td class="views-field views-field-name">Wanda</td>
<td class="views-field views-field-field-id">4</td>
<td class="views-field views-field-phpcode-1">
<a class="existing_submit disabled" href="...">Edit</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to reset?" href="...">Reset</a>
<div style="clear: left;"></div>
<a class="existing_submit disabled" href="...">Import</a>
<a class="existing_submit disabled" target="_blank" href="...">View</a>
<a class="existing_submit" target="_blank" href="...">Replay</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to submit the results?" href="...">Submit</a>
<a class="existing_submit" target="_blank" href="...">Print</a>
</td>
</tr>
<tr class="odd views-row-last">
<td class="views-field views-field-phpcode">
<img title="Ready" src="..."><br>Ready
</td>
<td class="views-field views-field-name">Herman</td>
<td class="views-field views-field-field-id">5</td>
<td class="views-field views-field-phpcode-1">
<a class="existing_submit disabled" href="...">Edit</a>
<a class="existing_submit confirm-submit" rel="Are you sure you want to reset?" href="...">Reset</a>
<div style="clear: left;"></div>
<a class="existing_submit" href="...">Import</a>
<a class="existing_submit" target="_blank" href="...">View</a>
<a class="existing_submit" target="_blank" href="...">Run</a>
<a class="existing_submit confirm-submit disabled" rel="Are you sure you want to submit the results?" href="...">Submit</a>
<a class="existing_submit disabled" target="_blank" href="...">Print</a>
</td>
</tr>
</tbody>
</table>
Capybara正在使用Selenium,所以我可以看到它加载的页面,而且这个表格与Capybara似乎看不到的东西相似。
以前有人见过这样的事吗?任何想法为什么会发生?
答案 0 :(得分:0)
似乎Capybara和Nokogiri之间存在脱节。使用native
属性可提供正确的值:
page.all('table tr').map { |e| e.native.text }
不幸的是,过滤器也会受到影响,因此以下操作无效:
page.should have_selector("table", :text => "Harvey")