Currently I am going through a situation. There are three rows in a the body of the table. I have to perform some action on each row if row matches with a text. For this I am getting the size for the the rows and using for loop and checking the condition. When condition are met, I have to perform some action by which the row is getting removed from the webtable which is as per my expectations. Further, I am getting org.openqa.selenium.StaleElementReferenceException: here "totalOrders.get(i).click();" when the loop try to perform action in next row here
here is some part of my code:
By loading = By.xpath("//div[@class='loading-wrap']");
By orders = By.xpath("//tbody/tr"); //this retruns 3 row
public void invoiceAllStockOrder() {
eu.waitForInvisibilityOfElementLocated(loading, 10);
List<WebElement> totalOrders = eu.getElements(orders);
int rowSize =totalOrders.size();
if(rowSize == 0) {
System.out.println("No order");
}
else {
for (int i = 0; i < totalOrders.size(); i++) {
eu.waitForInvisibilityOfElementLocated(loading, 10);
totalOrders.get(i).click();//getting stale element exception here when i = 1 but there are still 2 rows left
selectInstockOrders();
invoiceOrder();
}
}
}