Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从量角器中的browser.wait()返回ElementFinder?_Javascript_Angularjs_Protractor - Fatal编程技术网

Javascript 如何从量角器中的browser.wait()返回ElementFinder?

Javascript 如何从量角器中的browser.wait()返回ElementFinder?,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,在我的测试用例中,我试图在返回一些项目之前实现检查元素数组的helper。若数组不包含元素—我需要等待(我对应用程序的性能有一些问题,有时列表中的元素加载太长,同步无法工作) “我的助手”中的函数: getElementFromArray(array, elementIndex) { return browser.wait(() => { return array.count((count) => { return count >

在我的测试用例中,我试图在返回一些项目之前实现检查元素数组的helper。若数组不包含元素—我需要等待(我对应用程序的性能有一些问题,有时列表中的元素加载太长,同步无法工作)

“我的助手”中的函数:

getElementFromArray(array, elementIndex) {
    return browser.wait(() => {
        return array.count((count) => {
            return count > elementIndex;
        });
    }, 10000).then(() => {
        return array.get(elementIndex);
    }, () => {
        console.log("Element in array does not exist.");
        return null;
    })
}
然后我用它:

let row = helper.getElementFromArray(rowsCatalog, indexRow);
row.getText();
但是我得到了错误,因为
browser.wait()
返回
ManagedPromise
而不是
ElementFinder


我真的不想使用helpers函数作为承诺,因为它会使代码变得非常复杂和不可读(上面的示例是最简单的情况)。

不确定这是否适用于您的情况,但您可以在
浏览器之后返回。wait()


不确定这是否适用于您的情况,但您可以在
浏览器之后返回。wait()

getElementFromArray(array, elementIndex) {
    browser.wait(() => {
        return array.count((count) => {
            return count > elementIndex;
        });
    }, 10000);

    return array.get(elementIndex);
}