protected void assertElementNotStale() {
SgmlPage elementPage = element.getPage();
Page currentPage = parent.lastPage();
if (!currentPage.equals(elementPage)) {
throw new StaleElementReferenceException(
"Element appears to be stale. Did you navigate away from the page that contained it? "
+ " And is the current window focussed the same as the one holding this element?");
}
// We need to walk the DOM to determine if the element is actually attached
DomNode parent = element;
while (parent != null && !(parent instanceof HtmlHtml)) {
parent = parent.getParentNode();
}
if (parent == null) {
throw new StaleElementReferenceException("The element seems to be disconnected from the DOM. "
+ " This means that a user cannot interact with it.");
}
}