I am trying to iterate between all the options of a drop down and it works fine with the first option. After second option, I get stale Element Exception.
Below is the trace:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
Below is my code:
WebElement element = login.clickonCustomer();
Select select = new Select(element);
List<WebElement> listofelements = select.getOptions();
for (int i = 1; i < listofelements.size(); i++) {
String elementText = listofelements.get(i).getText();
System.out.println(elementText);
select.selectByVisibleText(elementText);
login.ClickonLogin().click();
Thread.sleep(3000);
Accounts.clickonLogout().click();
}
}