Recall & Review
beginner
What is a
StaleElementReferenceException in Selenium?It happens when you try to use a web element that is no longer attached to the current page's DOM. This means the element was found before but the page changed or refreshed, so Selenium can't find it anymore.
Click to reveal answer
beginner
Why does
StaleElementReferenceException occur during test automation?Because the web page changed after the element was found. For example, the page refreshed, or JavaScript updated the page, removing or replacing the element.
Click to reveal answer
intermediate
How can you handle
StaleElementReferenceException in Selenium Python?You can catch the exception and then find the element again before using it. This refreshes the reference to the current element in the page.
Click to reveal answer
intermediate
What is a common pattern to retry finding an element after
StaleElementReferenceException?Use a loop with a try-except block that tries to find and use the element. If the exception happens, catch it and retry a few times before failing the test.
Click to reveal answer
intermediate
Show a simple Python code snippet to handle
StaleElementReferenceException when clicking a button.from selenium.common.exceptions import StaleElementReferenceException
for _ in range(3):
try:
button = driver.find_element('id', 'submit')
button.click()
break
except StaleElementReferenceException:
continueClick to reveal answer
What does
StaleElementReferenceException mean in Selenium?✗ Incorrect
This exception means the element was found before but the page changed and the element is no longer valid.
Which action can help fix
StaleElementReferenceException?✗ Incorrect
Refreshing the page or re-finding the element updates the reference to the current DOM.
What is a good practice to avoid
StaleElementReferenceException?✗ Incorrect
Finding elements just before using them reduces the chance they become stale.
In Python Selenium, which exception class handles stale element errors?
✗ Incorrect
StaleElementReferenceException is the specific exception for stale elements.
What is the best way to retry an action after catching
StaleElementReferenceException?✗ Incorrect
Retrying with a loop and catching the exception allows the test to recover gracefully.
Explain what causes a
StaleElementReferenceException and how you can handle it in Selenium Python.Think about how web pages change and how Selenium keeps references.
You got /4 concepts.
Describe a simple Python code approach to retry clicking a button if a
StaleElementReferenceException occurs.Focus on catching the exception and retrying the find and click.
You got /4 concepts.