0

I have a grid with pagination enabled and I need to navigate through the pages to find required row and click on it using protractor. I can click on a specific row in the 1st page but if it's not on the first page so I need to click next page and check for the required row.

element.all("by.id('value').filter((row) => {
  return row.getText().then((text) => {
    if (text.indexOf(text) != -1) {
      return true;
    }
  });
}).then((rows) => {
  if (rows)
    rows[0].element(by.name('name')).click();
});

Below code is running 5 times even if the element is found on 1st page

for(i=0;i<5;i++) {
  ( (i) =>{
    console.log('I:'+i);
    element.all("by.id('value').filter((row) => {
      return row.getText().then((text) => {
        if (text.indexOf(someval) != -1) {
          return true;
        }
      });
    }).then((rows) => {  
        if(matchingRows.length>0){
     matchingRows[0].element(by.css(this.button)).click();
        return;
      }
    });
  })(i);
next.click();
 }
}
Ashish Deshmukh
  • 448
  • 4
  • 17
Karthi
  • 479
  • 2
  • 9
  • 21
  • Do a `for` loop to navigate trough pages, in it add a `if` condition, if the element is found then click it and return. – lauda Aug 09 '17 at 19:44
  • in for loop how to break element.all promise as I need to use element.all for each iteration in for loop? – Karthi Aug 09 '17 at 20:14
  • Use the loop for page numbers, the loop should look like this one from this answer https://stackoverflow.com/questions/21634558/looping-on-a-protractor-test-with-parameters Another example https://stackoverflow.com/questions/45015191/asynchronously-working-of-for-loop-in-protractor – lauda Aug 09 '17 at 20:19
  • Will this loop run through all the pages right? If I have 10 pages and I found the element in 5th page how should I come out of the loop? – Karthi Aug 09 '17 at 21:09
  • Add an `if` condition, if element is found, click it and `return true;` – lauda Aug 09 '17 at 21:14
  • @lauda, please check modified code. return is not working after the click. – Karthi Aug 09 '17 at 23:30

0 Answers0