Recall & Review
beginner
What is a StaleElementReferenceException in Selenium?
It is an error that occurs when a web element you are trying to interact with is no longer attached to the current page's DOM. This usually happens if the page refreshed or the element was updated.
Click to reveal answer
beginner
Why does StaleElementReferenceException happen?
Because the element reference is outdated. The page or part of it changed after you found the element, so Selenium cannot use the old reference anymore.
Click to reveal answer
intermediate
How can you handle StaleElementReferenceException in your test code?
You can catch the exception and then find the element again before retrying the action. This refreshes the element reference to the current page state.
Click to reveal answer
intermediate
Example code snippet to retry clicking an element after catching StaleElementReferenceException?
try {
element.click();
} catch (org.openqa.selenium.StaleElementReferenceException e) {
element = driver.findElement(By.id("elementId"));
element.click();
}
Click to reveal answer
beginner
What is a good practice to avoid StaleElementReferenceException?
Avoid storing web elements for a long time. Instead, find elements fresh right before interacting with them to ensure they are current.
Click to reveal answer
What does StaleElementReferenceException indicate in Selenium?
✗ Incorrect
StaleElementReferenceException means the element reference is outdated because the element is no longer attached to the current DOM.
Which is a common way to fix StaleElementReferenceException?
✗ Incorrect
Catching the exception and re-finding the element refreshes the reference and fixes the issue.
When is StaleElementReferenceException most likely to occur?
✗ Incorrect
The exception happens if the page reloads or the element changes after you found it.
What is NOT a good practice to avoid StaleElementReferenceException?
✗ Incorrect
Storing element references for a long time can cause stale references and exceptions.
Which Selenium method helps to find an element again after a stale reference?
✗ Incorrect
driver.findElement() locates the element fresh from the current DOM.
Explain what causes StaleElementReferenceException and how you can handle it in Selenium tests.
Think about what happens when the page changes after you find an element.
You got /5 concepts.
Describe best practices to avoid StaleElementReferenceException in your Selenium automation scripts.
Focus on how to keep element references current and stable.
You got /4 concepts.