Q&A
Systematic approach to fixing StaleElementReferenceException in Selenium?
Ajitesh MohantaAmbassador
May 15, 2026 1,190 0
StaleElementReferenceException is the bane of our Selenium suite. We get maybe 20–30 per CI run across 800 tests, mostly on pages that have React re-renders.
Current approach: retry the element lookup up to 3 times with a small sleep. It works but it's ugly and slow.
Is there a cleaner pattern? I've seen approaches using:
- A custom `findElement` wrapper that retries on stale
- `ExpectedConditions.refreshed()` which I don't fully understand
- Moving to relative locators to avoid stale references
Looking for a solution that's clean enough to enforce team-wide.