在 Ruby Watir 中使用 XPath 进行健全性检查
我正在使用 Ruby Watir 库为客户端进行自动化测试,但 XPath 选择器出现问题。 我想我只是需要另一双眼睛让我知道我是否错过了什么。
这是我正在使用的选择器:
puts ie.cell(:xpath, "//img[@src='3.jpg']/../").text
对于这组表,它按预期工作并打印“第三张图像”:
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="2.jpg">Second Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
但是当我删除第二个表时,它正在破坏:
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
使用上面的 put 代码,我在第二个示例中收到此错误:
Watir::Exception::UnknownObjectException: Unable to locate element, using :xpath, "//img[@src='3.jpg']/../"
I'm using the Ruby Watir library to do automated testing for a client and I'm having issues with the XPath selector. I think I just need another set of eyes to let me know if I'm just missing something.
Here is the selector I'm using:
puts ie.cell(:xpath, "//img[@src='3.jpg']/../").text
For this set of tables, it works as expected and prints "Third Image":
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="2.jpg">Second Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
But is is breaking when I remove the second table:
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg">Third Image</td>
</tr>
</table>
Using the puts code above I get this error on the second example:
Watir::Exception::UnknownObjectException: Unable to locate element, using :xpath, "//img[@src='3.jpg']/../"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我重现了这个问题,并重新启动浏览器(IE6)为我修复了它。
I reproduced the problem, and restarting the browser (IE6) fixed it for me.
对于当前版本的 Watir,更好的方法是
browser.img(:src => '3.jpg').parent.text
For current versions of Watir the better way to do this would be
browser.img(:src => '3.jpg').parent.text