Use waiting matchers for h1 content expectations#317
Merged
Conversation
expect(page.find("h1")).to have_content finds an h1 first and
then checks its text. If the find runs while the browser is
mid-navigation it either fails with ElementNotFound on a blank
document, or grabs the outgoing page's h1 which then goes stale.
expect(page).to have_css re-runs the whole query on every retry,
so it recovers from both.
lfdebrux
approved these changes
Jul 24, 2026
lfdebrux
left a comment
Contributor
There was a problem hiding this comment.
I'm not sure it will make a difference to the errors we were seeing (or how we would tell now the default wait time has been increased), probably won't hurt though.
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
Replaces all
expect(page.find("h1")).to have_content "X"assertions withexpect(page).to have_css "h1", text: "X". A purely mechanical pattern swap — no headings or call sites change.Why
The find-then-assert form races against navigation.
page.find("h1")runs first and in the pipeline this intermittently either:ElementNotFound: Unable to find visible css "h1"because the document is momentarily blank mid-navigation, orhave_contentcheck, raisingStaleElementReferenceErrorexpect(page).to have_css "h1", text: "X"re-runs the whole query (element and text together) on every retry, so it recovers from both a late-rendering page and a stale node.Follows on from #315, which gave these matchers a long enough retry window.