Skip to content
CodeKruPro

Recover after an element goes stale

Automation taskMediumPython onlyAsked in: Accenture, Capgemini, TCS

Interviewers ask: "What is a stale element, and how do you fix it?" Find an element, refresh the page, watch the old reference fail with StaleElementReferenceException, then find the element again. The refresh replaced the element, so the old reference points at nothing.

Recover After an Element Goes Stale

Recover After an Element Goes Stale

A found element points at a node. After refresh() that node is gone. Using it raises StaleElementReferenceException. Find the element again.

Task:

  1. Find #preFilledTextField
  2. Refresh the page and use the old element
  3. Print whether that use raised StaleElementReferenceException
  4. Find the field again and print its value

Print the lines below exactly.

Expected output:

Stale: True
Value: Codekru