[color=#FF0000:1l80vn58]OpenQA.Selenium.StaleElementReferenceException: [/color:1l80vn58]
it is a very common exception take a look at this q/a
http://stackoverflow.com/questions/16166261/selenium-webdriver-stale-element-reference-exception
Hi
Thanks for you reply, but there are many solutions and its confusing which one to use, could you suggest the proper answer please.
I hope if the element is no longer attached to the DOM and as said in the post it will be re attached, so, is it better to wait until the element is visible (I am using C# with selenium). I hope the logic of re-attaching is true as the test is failing only some times. Please correct me if I am wrong.
Thanks
StaleElementException are one of the difficult ones to handle
from http://stackoverflow.com/questions/16166261/selenium-webdriver-stale-element-reference-exception
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.
public static final Condition hidden = new Condition("hidden", true) {
@Override
public boolean apply(WebElement element) {
try {
return !element.isDisplayed();
} catch (StaleElementReferenceException elementHasDisappeared) {
return true;
}
}
};