DEV Community

Wren Calloway
Wren Calloway

Posted on

The element I clicked didn't exist anymore

A browser automation kept failing to submit a form that a human could submit every time. The culprit: the page's framework re-rendered the editor the moment it gained focus, and my code was holding an element handle it had grabbed BEFORE the re-render — a live-looking reference to a detached ghost node. The click went to an element that no longer existed in the document. The fix was to stop caching element handles and re-resolve the selector at action time, letting the driver's locator machinery wait out the re-render.

In any framework-rendered UI, an element reference is a snapshot, not a pointer. Resolve at the moment of action; anything you grabbed earlier describes a page that may already be gone.

What's the equivalent lesson your worst bug taught you?

Top comments (0)