Repository navigation
Fix stale element and pending request waits (1.1.0) - #9
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
A local demo (one checkout flow, 50 seeded runs per version, headless Chrome 156, waitless 1.0.5) found two problems:
network_idle_threshold=2, one in flight cart call counted as stable, so Checkout was clicked under a "Saving..." overlay. Default config passed 24/50; all 26 failures wereElementClickInterceptedExceptionat the Checkout click.strictness="strict", network_idle_threshold=0,find_elementreturned the first button as soon as it appeared, thenclick()waited for the prices call that redraws the list, so the held element was stale. Strict passed 3/50; all 47 failures wereStaleElementReferenceExceptionat the Add to cart click.On the same seeds:
time.sleep(1)style 23/50, hand writtenWebDriverWait50/50 (median 4.75 s).Behavior changes (why this is 1.1.0, not a patch)
network_idle_thresholdis now 0 (was 2), andStabilizationConfig.strict()sets 0 explicitly. All tracked XHR/fetch requests must finish before an interaction.relaxed()still uses 2.click()waits foris_enabled(). A button that never becomes enabled now raisesTimeoutExceptionwith the tag, text and timeout (for exampleElement <button> 'Click' was not enabled after 2.0s) instead of a silent no op click.find_element()settles twice: settle, find, settle again, find again, and returns the fresh element.find_element(): settle, look up again with the same locator, compare a fingerprint captured when the element was found, and click only if it matches. The fingerprint is tag, visible text,id,name,data-testid,aria-label, the element's index among the locator's matches, and its parent's visible text (element and parent text capped at 200 characters), read in one script call inside the timeout budget. Otherwise it raisesStaleElementReferenceExceptionsaying it refused to click a different element. Elements fromfind_elements()orexecute_script()do not retry.NoSuchElementExceptionsaying it is no longer on the page, and a failedfind_element()keeps Selenium's original not found message.click()/find_element()call across stabilization, polling and retry waits.Upgrade note
Apps with constant polling, analytics or long polling can set
StabilizationConfig(network_idle_threshold=2)to get the 1.0.5 allowance back. Tests that click disabled elements on purpose will now wait for the timeout and raise. A stale retry now refuses (raisesStaleElementReferenceException, as plain Selenium would) when the replacement's text or parent text changed, for example a row whose counter changed. The fingerprint still cannot tell apart elements that match on all of those fields, including parent text (for example identical Delete buttons in rows that differ only in hidden attributes).Files
waitless/selenium_integration.py: shared deadline helpers, fresh lookup after settle, enabled wait, fingerprint guarded stale retry with a single script snapshot.waitless/config.py: zero default and strict thresholds.tests/integration/test_click_regressions.py(16 browser regressions),tests/unit/test_selenium_wrappers.py,tests/unit/test_config.py.pyproject.tomlandwaitless/__init__.py.Not released, tagged or published.