如何检测 Watir 中是否存在元素 [英] How to detect if an element exists in Watir

查看:19
本文介绍了如何检测 Watir 中是否存在元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Watir 比较陌生,但找不到关于如何检查元素是否存在的好的文档(示例).当然有 API 规范,但如果我找不到示例,这些规范对我来说意义不大.

I'm relatively new to Watir but can find no good documentation (examples) regarding how to check if an element exists. There are the API specs, of course, but these make precious little sense to me if I don't find an example.

我已经尝试了两种组合,但似乎没有任何效果...如果 browser.image (:src "/media/images/icons/reviewertools/editreview.jpg"). 存在然后...如果 browser.image (:src "/media/images/icons/reviewertools/editreview.jpg"). 存在?然后……

I've tried both combinations but nothing seems to work... if browser.image (:src "/media/images/icons/reviewertools/editreview.jpg").exists then... if browser.image (:src "/media/images/icons/reviewertools/editreview.jpg").exists? then...

如果有人对如何实现这一点有具体的建议,请帮忙!谢谢!

If anyone has a concrete suggestion as per how to implement this, please help! Thanks!

推荐答案

参数之间似乎缺少逗号.

It seems you are missing a comma between parameters.

应该是

if browser.image(:src, "/media/images/icons/reviewertools/editreview.jpg").exists?

您还可以找到此页面将来知道支持哪些属性.

Also you can find this page useful in future to know what attributes are supported.

这篇关于如何检测 Watir 中是否存在元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆