等待元素存在而没有错误 [英] wait for element present without error

查看:70
本文介绍了等待元素存在而没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在夜表中调用waitForElementPresent,而不会错误地指出该元素是否不存在?

is there a way to call waitForElementPresent in nightwatch without erroring out if the element is not there?

现在,如果将false作为第三个参数传递,您仍然会看到错误.理想情况下,我想要一个等待元素的函数,如果找不到元素,则返回该函数.

Right now, if you pass in false as the third parameter, you still see an error. Ideally, I would like a function that waits for an element, and returns if it didn't find the element.

推荐答案

您可以做到:

  Browser.waitForElementPresent('@element',3000,false, function(result){
    If(result.value === true){
    // test if element present
    }else{
    // test if element not present
    }
  })

从第一天开始,我就这样做了,这段代码的问题是守夜人会将失​​败的测试视为通过的测试,如您所见,上面的代码处理两个结果值.

Since the day one, i did this and the problem with this code is nightwatch would count a failed test as a passed test,as you see above code handle both result value.

所以我建议让夜表本身返回错误,为差值编写差值函数.

So i recommend let the nightwatch return error itself, write difference function for difference value.

这篇关于等待元素存在而没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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