stale element exceptions are very hard to handle.
First of all lets be clear about what a WebElement is.
A WebElement is a reference to an element in the DOM.
A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated.
When this happens the reference to the element in the DOM that you previously had becomes stale and you are no longer able to use this reference to interact with the element in the DOM. When this happens you will need to refresh your reference, or in real world terms find the element again.
This is not a problem. If you wrap your .findElement call in a try-catch block and catch the StaleElementReferenceException , then you can loop and retry as many times as you need until it succeeds.
Here are some examples I wrote.
Another example from Selenide project:
[code:2eo8d2xj]
public static final Condition hidden = new Condition("hidden", true) {
@Override
public boolean apply(WebElement element) {
try {
return !element.isDisplayed();
} catch (StaleElementReferenceException elementHasDisappeared) {
return true;
}
}
};
[/code:2eo8d2xj]
if above doesn't work then try this blog
http://darrellgrainger.blogspot.com/2012/06/staleelementexception.html