如何处理量角器中找不到元素的异常 [英] How to handle element not found exception in Protractor

查看:94
本文介绍了如何处理量角器中找不到元素的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像Selenium Webdriver为Java提供了各种异常处理一样,我们有什么方法可以使用Protractor实现相同的功能.

Just like Selenium webdriver provides various Exception handling for Java, is there any way we can achieve same using Protractor.

如果我们要处理找不到元素的异常,那么使用量角器的最佳方法是什么?

If we want to handle element not found exception, then what is the best way to do it using Protractor?

推荐答案

此问题的答案

当命令无法完成时,WebDriver会引发错误-例如无法点击被另一个元素遮挡的元素.如果您需要重试这些操作,请尝试使用 webdriverjs-retry .如果您只是想捕捉错误,请这样做

WebDriver throws errors when commands cannot be completed - e.g. not being able to click on an element which is obscured by another element. If you need to retry these actions, try using webdriverjs-retry. If you would just like to catch the error, do so like this

适合您的问题:

elm.isPresent().then(function(present) {
  /* no webdriver js errors here */}
  if (present) {
    /* element exists */
  } else {
    /* element doesn't exist */
  }
, function(err) {
  /* error handling here, i.e. element doesn't if got ElementNotFound
     but, eventually and less likely, other issues will fall in here too like
     NoSuchWindowsError or ElementStaleError etc...
  */
});

这篇关于如何处理量角器中找不到元素的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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