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

前端 未结 4 1890
隐瞒了意图╮
隐瞒了意图╮ 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:49

    The syntax could be little off. Not very familiar with NightWatchJS. However the concept remains same.

    //I would not wait for a element that should not exist
    //rather I would find the list of the element and see if the count is greater than 0
    //and if so, we know the element exists
    browser.findElements(webdriver.By.css('#advanced-search')).then(function(elements){
        if(elements.length> 0){
            console.log(elements.length);
        }
    });
    

    See some more example here

提交回复
热议问题