Nightwatchjs: how to check if element exists without creating an error/failure/exception

前端 未结 4 1889
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 15:11

In the page I\'m testing, two buttons may be displayed: BASIC or ADVANCED.

I want to be able to tell if the ADVANCED button is showing -- and if so, click it.

<
4条回答
  •  星月不相逢
    2021-01-01 15:36

    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
        }
    });
    

提交回复
热议问题