gpt4 book ai didi

javascript - 如何处理 Protractor 中未找到元素的异常

转载 作者:数据小太阳 更新时间:2023-10-29 04:07:08 24 4
gpt4 key购买 nike

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

如果我们想处理元素未找到异常,那么使用 Protractor 的最佳方法是什么?

最佳答案

这个问题的答案is now in Protractor's FAQ

如何捕获 ElementNotFound 等错误?

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...
*/
});

关于javascript - 如何处理 Protractor 中未找到元素的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22550329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com