Loop through a process depending on positive and negative scenario

Here you can see a tabular data.
Here we have to click on first blue icon. After clicking on that there 2 scenarios.

Positive Scenario
Once click on that icon if it has processed successfully the site will refresh and the first row will disappear and second row will come on top and so on.

Negative scenario.
After clicking the icon if the process is not successful it will stay there and then we have to click on next icon

Since we are using counter
In positive scenario after the first one disappears it should select the row which now appeared on top, but it is selecting the second row.

In negative it is going properly one by one.

But this scenarios can appear any time.

So can someone give any solution to this thankyou.