如何将地图函数应用于ElementArray Finder中的每个元素

时间:2017-04-06 13:16:53

标签: dictionary callback promise protractor

我试图循环,根据文本进行比较,如果匹配则单击元素。

我偶然发现了以下帖子,这非常有帮助

Passing Protractor ElementFinder to deferred.fulfill() results in a promise containing a null value

根据上述帖子中提供的答案,我实现了这个

  element.all(by.css('.classname')).map(function (elm, index) {

        return {
             elm: elm,
            text: elm.getText(),
            index: index

        };
    }).then(function (list) {

        for (var i = 0; i < list.length; i++) {
            if (list[i].text === 'DS_Emulator') {

                return list[i].elm;
            }
        }
        throw new error('Text not found');
    }).then(function (elm) {

          elm.click();           

        });

    });

这使应用程序退出而没有任何错误。由于地图中的榆树:榆树,这种情况正在发生。

如果我修改我的代码如下,应用程序工作正常。

 element.all(by.css('.classname')).map(function (elm, index) {

        return {
           // elm: elm,
            text: elm.getText(),
            index: index

        };
    }).then(function (list) {

        for (var i = 0; i < list.length; i++) {
            if (list[i].text === 'DS_Emulator') {

                return list[i].index;

              //  return list[i].elm;
            }
        }
        throw new error('Text not found');
        }).then(function (elm) {

          //  elm.click();

            element.all(by.css('.classname')).then(function (items) {

                items[elm].click();

            });

    });

请帮助我了解我哪里出错了。

0 个答案:

没有答案