我有以下片段
,clickStaleElement: function(remote, id) {
return remote
.findById(id)
.execute(function(id){
//force org.openqa.selenium.StaleElementReferenceException
$(document.getElementById(id)).addClass('hidden');
},[id])
.click()
.catch(function(){
return this.parent
.findById(id)
.execute(function(id){
//bring back the element
$(document.getElementById(id)).removeClass('hidden');
},[id])
.click()
.end()
;
})
.end()
;
}
应该处理StaleElementReferenceException
,或任何其他的,并尝试再次找到该元素并单击它。该元素以固定间隔添加到dom或从dom中删除,因此有时我在测试运行中遇到此异常,因此运行失败。我想处理这个异常并防止运行失败,因为实际上并没有因为错误而失败(或者是吗?)。
所以问题是如何处理该.click()
方法的异常?