Repository navigation
Conversation
ElementNotFound becomes an Error subclass that explains itself. Right
after it is created it runs one script in the page through the active
web helper's executeScript and appends hints to its message and stack:
a match inside a same-origin iframe (with the within({ frame }) call),
matches excluded by within() or hidden, and up to 3 similar ids, classes
or element names. explain() returns the pending work for callers that
need to wait, and MCP run_code awaits it.
No helper, hook or core change: works for Playwright, Puppeteer,
WebDriver, CDPBrowser and their subclasses as they are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DavertMik
force-pushed
the
feat/playwright-explain-not-found
branch
from
November 13, 2026 10:15
06ec8c7 to
4197668
Compare
…ame hint ElementNotFound is now an Error subclass, so Scenario().fails() and throws(new Error()) must match subclasses instead of comparing constructor names exactly. Lightpanda returns no iframe contentDocument, so the iframe hint test is skipped there. Restores the MultipleElementsFound test that still uses fetchDetails(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
When a locator matches nothing,
ElementNotFoundnow adds hints about what the page has instead:Hints cover:
within({ frame })call to usewithin()context, or hidden onesDesign
All the logic lives in
lib/helper/errors/ElementNotFound.js:ElementNotFoundbecomes anErrorsubclass.executeScript(found via the container), capped at 500 ms.messageandstack, about 10 ms after the throw, while the page is still open.err.explain()returns that pending work for callers that need to wait. MCPrun_codeawaits it (one line inbin/mcp-server.js).No helper, hook, recorder, step or CLI changes. It works as-is for Playwright, Puppeteer, WebDriver and CDPBrowser (and Lightpanda, Obscura, Kitesurf, Moli, Appium through inheritance).
Not named
fetchDetails, on purpose: the CLI awaitsfetchDetails()after mocha'send, and nothing waits for that work to finish. With it, the whole failure report was lost underrun-workers. The same race already affectsMultipleElementsFoundon4.x: its failure details don't print, even in a single-process run. That's left for a separate fix.Limitations
Tested locally
test/unit/helper/element_not_found_test.js: 9 passing (message format, hints from page info, page script failure, unanswered page).#explainNotFoundin the sharedtest/helper/webapi.js: Playwright 4/4, Puppeteer 4/4, CDPBrowser (Chrome) 4/4. Plus one Playwright hidden-match test withvisibleLocator.codecept runandrun-workers 2both print the hint once, with a clean stack.npm run defand eslint pass.🤖 Generated with Claude Code