Repository navigation
Conversation
…ions element_to_be_clickable, element_located_to_be_selected and visibility_of_any_elements_located call is_displayed, is_enabled or is_selected without catching StaleElementReferenceException. When the page re-renders between finding the element and checking it, the exception escapes WebDriverWait.until, which by default only ignores NoSuchElementException, so the wait fails at once instead of polling again. Return False on a stale element, as visibility_of_element_located, visibility_of_all_elements_located and the Java bindings' ExpectedConditions.elementToBeClickable already do, so the wait retries.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Thank you, @Mohsintl for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
There was a problem hiding this comment.
Expected Conditions do handle stale elements inconsistently, but I'm not sure about changing behavior that could potentially break existing code relying on the current semantics.
You can already add any exception to WebDriverWait's ignored_exceptions if you want it ignored when using an Expected Condition.
@AutomatedTester any thoughts?
🔗 Related Issues
None filed. The bug is small and the reproduction is below.
💥 What does this PR do?
element_to_be_clickable,element_located_to_be_selectedandvisibility_of_any_elements_locatedcallis_displayed(),is_enabled()oris_selected()without catchingStaleElementReferenceException.If the page re-renders between finding the element and checking it (common with React, Vue or Angular), the exception escapes
WebDriverWait.until. The wait only ignoresNoSuchElementExceptionby default, so it fails right away instead of polling again:This PR makes these conditions return
Falseon a stale element, so the wait retries.🔧 Implementation Notes
This uses the same
try/except StaleElementReferenceException: return Falsethatvisibility_of_element_located,visibility_of_all_elements_locatedandelement_located_selection_state_to_bealready use. It also matches Java, whereExpectedConditions.elementToBeClickable(By)andelementToBeClickable(WebElement)catchStaleElementReferenceExceptionand keep polling.When
element_to_be_clickableis given aWebElementthat goes stale, it now keeps waiting until the timeout, which is also what Java does.The new unit tests in
py/test/unit/selenium/webdriver/support/expected_conditions_tests.pyuse a mocked element whose checks raiseStaleElementReferenceException. All 4 fail without the fix and pass with it.🤖 AI assistance
💡 Additional Considerations
None.
🔄 Types of changes