Take elements while a condition evaluates to true (extending ElementArrayFinder)

后端 未结 2 1505
孤城傲影
孤城傲影 2020-11-29 10:57

We have a menu represented as a ul->li list (simplified):

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 11:29

    Maybe I'm missing something, but couldn't you just go through ul li a elements while they gave you something from getText(), and store them to some array, or do something with them directly in that loop?

    var i = 0;
    var el = element.all(by.css('ul li a'));
    var tableItems = [];
    (function loop() {
        el.get(i).getText().then(function(text){
            if(text){
                tableItems.push(el.get(i));
                i+=1;
                loop();
            }
        });
    }());
    

提交回复
热议问题