我有以下HTML代码,并且不确定是否可以在水豚中为“查找”构建选择器以获取所需的元素。我在Rails项目中将水豚用于黄瓜。(生成HTML)
<tbody>
<tr>
<td>Heine</td>
<td><a href="/customers/1">Show</a></td>
<td><a href="/customers/1/edit">Edit</a></td>
<td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/customers/1">Destroy</a></td>
</tr>
<tr>
<td>IKEA</td>
<td><a href="/customers/2">Show</a></td>
<td><a href="/customers/2/edit">Edit</a></td>
<td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/customers/2">Destroy</a></td>
</tr>
<tr>
<td>testcustomer</td>
<td><a href="/customers/5">Show</a></td>
<td><a href="/customers/5/edit">Edit</a></td>
<td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/customers/5">Destroy</a></td>
</tr>
如何在第一个td包含“ testcutomer”的行中“找到” href“编辑”?谢谢你。
您可以使用以下内容:
find("td", :text => /\Atestcustomer\z/).first(:xpath,"..").find("a", :text => /\AEdit\z/)
find("td", :text => /\Atestcustomer\z/)
为您td
提供带有文本“ testcustomer”的,然后td
使用来找到该文本的父项,first(:xpath,"..")
然后使用来找到文本为“编辑”的锚点标签find("a", :text => /\AEdit\z/)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句