samedi 7 novembre 2020

How to break out of FOR loop if the condition is met? For loop only loops through the last element. What am I doing wrong? [duplicate]

Im trying to loop through a set of cards, and if the the title of the card's child matches with the text Im passing, It should click on the title of the card's link. So far, It loops only through 9th element.

ElemCount = 9 (0-8)
Console.log(i) is always 9.
Please help me with this. Im new to javascript. Please let me know if I need to clarify anything here. Thanks in advance.

     $$(utils.SELECTORS.RESULT_TITLE).count().then(function (elemCount) {
         for(var i = 0; i < elemCount; i++;) {
             var elem = $$('.result-card-module__ResultCardContainer .result-card-module__ResultCardLeft > div:nth-child(3) > p').get(i);
             elem.getText().then(function (text) {
               if(text === objectType) {
                    elem.get(i).click();
                     verifyObjectPath('/xxx');
                }
             });
         }
}

Aucun commentaire:

Enregistrer un commentaire