首页 > 解决方案 > 如何解决量角器中 isDisplayed() 的承诺

问题描述

以下是我返回的代码:

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

解决方案


试试下面的代码。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');
    }
});

干杯!


推荐阅读