我试图使用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"]
Update:这是它试图处理的表:
<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似乎看到的任何东西。
有人见过这样的东西吗?知道为什么会这样吗?
看来水豚和野尻之间存在脱节。使用native
属性提供正确的值:
page.all('table tr').map { |e| e.native.text }
不幸的是,过滤器也会受到影响,所以下面的代码不能工作:
page.should have_selector("table", :text => "Harvey")