且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Nightwatchjs:如何在不创建错误/失败/异常的情况下检查元素是否存在

更新时间:2022-06-08 22:21:56

您可以使用 Selenium协议元素" 和一个回调函数,用于检查结果状态以确定是否找到了该元素.例如:

You can achieve this by using the Selenium protocol "element" and a callback function to check the result status to determine if the element was found. For example:

browser.element('css selector', '#advanced-search', function(result){
    if(result.status != -1){
        //Element exists, do something
    } else{
        //Element does not exist, do something else
    }
});