high

StaleElementReferenceException

The element previously located is no longer attached to the DOM. The page was refreshed, navigated, or the element was re-rendered by JavaScript.

Common Causes

  1. 1Page was refreshed or navigated after locating the element
  2. 2JavaScript framework re-rendered the component (React, Angular, Vue)
  3. 3AJAX call updated the DOM, replacing the element
  4. 4Element was in a list that was re-sorted or filtered

How to Fix

Re-locate the element before each interaction

// Python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, 'my-element'))
)
element.click()

Always re-find the element using explicit waits. Never store element references for later use across page interactions.

Use a retry pattern

// Java
public void clickWithRetry(By locator, int maxRetries) {
    for (int i = 0; i < maxRetries; i++) {
        try {
            driver.findElement(locator).click();
            return;
        } catch (StaleElementReferenceException e) {
            if (i == maxRetries - 1) throw e;
        }
    }
}

Wrap element interactions in a retry loop to handle transient staleness during DOM updates.

How ObserveOne Helps

ObserveOne detects DOM instability patterns and automatically retries interactions with stale elements.

Start Monitoring Free

Related Errors