【问题标题】:How to solve the promise for isDisplayed() in protractor如何解决量角器中 isDisplayed() 的承诺
【发布时间】:2019-07-07 01:24:05
【问题描述】:

下面是我返回的代码:

TypeError: 无法读取未定义的属性“then”

verifyElement(locator){
    var text = element(by.xpath(locator)).isDisplayed()
    text.then(function(result){
        console.log("Element is displayed");
        return true
    },
    function(error){
        console.log("Element is not displayed");
        return false;
    }
)}

【问题讨论】:

    标签: protractor


    【解决方案1】:

    试试下面的代码。 Promise 与箭头函数配合得很好。

    element(by.xpath(locator)).isDisplayed().then(status => {
        if(status){
            //code if element displayed
            assert(true,'Element is displayed');
        }else{
            assert(false,'Element is not being displayed');
        }
    });
    

    干杯!

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2014-08-08
      • 2016-05-04
      • 2015-03-06
      • 1970-01-01
      相关资源
      最近更新 更多