【问题标题】:How to find specific row in Protractor如何在量角器中查找特定行
【发布时间】:2018-09-06 19:13:01
【问题描述】:

所以这个问题基本上是要详细说明 [How to find specific row in ng-table by text [protractor] 中提到的解决方案是如何工作的。

我这里复制代码sn-p

element.all(by.repeater('item in $data track by    $index')).filter(function(row) {
    return row.getText().then(function(txt) {
        txt = txt.replace(/\s/g, '');
        var found = txt.split('ID0001');
        return found.length > 1;
    });
}).then(function( elem){
   elem[0].click();
});

在这里,我无法理解它是如何在 then 子句中专门选择 ID0001 的。我得到了使用 split 函数的部分,因为当什么都没有找到时,它会简单地返回 1 并且如果找到它,长度将大于并且因此将返回 true。但是,我很困惑它在哪里返回了我们想要找到的元素以便对其执行点击操作?

【问题讨论】:

    标签: angularjs selenium protractor automated-tests


    【解决方案1】:

    element.all().filter()用于从element.all()返回的元素列表中找出满足你要求的元素。

    filter() 的结果是一个新列表,其中可能包含element.all() 的全部/部分元素。

    filter() 需要一个函数作为参数。并且要求函数应该返回一个布尔值/承诺。当boolean/<promise<boolean>等于True时,迭代元素将被添加到返回的新列表中。

    其实element.all().filter()Array.filter差不多,你可以向here学习,帮助你理解前者。

    【讨论】:

      【解决方案2】:

      如果.split('ID0001') 成功,字符串将至少分成两部分,found.length > 1 将是true。如果返回true,则表示您拥有所需的元素,因此.then() 点击它。

      【讨论】:

        猜你喜欢
        • 2015-12-19
        • 1970-01-01
        • 1970-01-01
        • 2020-02-26
        • 2019-08-14
        • 2021-02-27
        • 2021-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多