我有一些带有onclick
属性和一些没有属性。我想检查指定的元素是否具有onclick
属性。我怎样才能做到这一点?
getAttribute()
当有属性值时返回该属性值。如果没有,它会抛出 RuntimeException 并停止测试(即使我将其包装在 try/catch 块中)。
$onclickValue = $this->getAttribute("$locator@onclick"); //works when the attribute exists
通过使用getEval()
,你可以执行javascripthasAttribute()
功能。使用findElement()
,将允许您使用任何类型的定位器模式。
$hasAttribute = $this->getEval('this.browserbot.findElement("' . $locator . '").hasAttribute("onclick")');
if ($hasAttribute === 'true') {
//attribute exists
}
注意getEval()
返回一个字符串,而不是布尔值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)