Selenium / Scenario
Anatomy of a Stale Element
A search test dies with StaleElementReferenceException on line 4, but only when the API is fast. Trace the reference that outlived its DOM node.
- Difficulty
- Medium
- Format
- Scenario
- Points
- 150
- Estimate
- 14 min
// MISSION BRIEF
Your Mission
The search results test fails roughly half the time with a stale element error, and the junior fix attempt (a try/catch that clicks anyway) made it worse. You have the test code, the failing trace, and one suspicious detail: it fails MORE often on the fast staging environment.
Diagnose the lifecycle bug and pick the durable fix. Decisions are weighted.
// FIRST CONTACT
Battle teaser
First artifact
SearchTest.java (excerpt)
Why does line 4 throw StaleElementReferenceException?
- AChrome 126 garbage-collects WebElements after 5 seconds
- BfindElements returns copies that expire after one use
- Crows was captured BEFORE the search; the re-render unmounted those DOM nodes, so the stored references point at elements that no longer exist
Answers, scoring, hints, and the full battle stay sealed.
// SKILL TAGS
seleniumstale-elementspadebuggingjava