{"schemaVersion":"1.0","canonicalUrl":"https://automationtester.in/failures/stale-element-reference-exception","slug":"stale-element-reference-exception","title":"Stale element reference exception","signature":"StaleElementReferenceException: stale element reference","frameworks":["Selenium"],"classification":"selector-drift","summary":"Selenium is holding a reference to a DOM node that the application replaced or detached after it was located.","causes":[{"title":"The framework re-rendered the component","explanation":"React, Vue, or another UI layer replaced the node after state changed.","diagnostic":"Check whether the failure follows navigation, filtering, or a network response.","fix":"Locate the element immediately before the interaction instead of caching WebElement references."},{"title":"The document or frame changed","explanation":"Navigation or frame replacement invalidated every reference from the previous document.","diagnostic":"Confirm the active URL and frame before the failed action.","fix":"Wait for navigation or frame attachment, switch context, and locate again."},{"title":"A polling loop reuses the same element","explanation":"Retry code may repeatedly act on a reference that cannot become valid again.","diagnostic":"Inspect whether the retry callback captures a WebElement outside the loop.","fix":"Put the locator lookup inside the wait or retry callback."}],"prevention":["Store locators, not element instances.","Wait on state changes, not sleep durations.","Keep frame transitions explicit."],"related":["element-not-visible-or-actionable","playwright-timeout-exceeded"],"references":[{"label":"Selenium stale element errors","url":"https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception"}]}