javascript - Protractor Looping Not Able to Click Correct Item -
looping through , trying print out console choice , clicking not working properly. each of list items have text , list item clickable. i'm trying iterate through list match text (choice_item), if matches prints console , clicks item.
but when check output, clicks next item after it. example, print:
item 1
item 2
choice found: item 2
item 3
and clicks item 3 instead of item 2 (the choice_item want find in list). explanation on how fix and/or control flow mistakes making appreciated!
this.getlistitems = function(choice_item){ var choice = ""; this.getselectionslist().filter(function(elem, index) { return elem.element(by.css('.choicename')).gettext().then(function(text) { if(text === choice_item){ console.log("choice found:"+ choice_item); choice = text; elem.click(); return true; } }); }).then(function(items) { expect(choice).tobe(choice_item); }); };
filter element choice_item
text , click it:
this.getlistitems = function(choice_item) { var listitems = this.getselectionslist().filter(function(elem) { return elem.element(by.css('.choicename')).gettext().then(function(text) { return text === choice_item; }); }); listitems.first().click(); };
note there no need expect()
here since applying choice_item
check while filtering list item.
Comments
Post a Comment