Pick the right element by its label when a click matches several - #162
Open
DavertMik wants to merge 1 commit into
Open
Pick the right element by its label when a click matches several#162DavertMik wants to merge 1 commit into
DavertMik wants to merge 1 commit into
Conversation
A click that matched more than one element asked the model to choose between them, but described each candidate with markup that had been stripped of everything nested inside it. A button whose label lives in child spans arrived as an empty shell, so two menu items reading "New test" and "New tests from requirement" were indistinguishable and the pick was a guess that opened the wrong screen and reported success. Each candidate now carries its own visible text, whitespace collapsed and capped, and its markup comes from the element's own outer HTML cleaned through the project's class filter rather than from an upstream simplifier that removes non-interactive descendants. Labels and meaningful class names survive; layout and generated styling classes do not, so the 300-character budget is spent on signal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JbhzmY1M51pyRysUx32MdP
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
I.click("New test")matches more than one element, CodeceptJS raisesMultipleElementsFoundand we ask the model which candidate to click. Each candidate was described by its markup alone — and that markup came fromtoSimplifiedHTML(), which strips non-interactive descendants. A button whose label lives in child spans arrives as an empty shell:Those are a New test menu item and a New tests from requirement menu item. They are indistinguishable, so the choice is a guess — and when it guesses wrong the click still succeeds, the wrong screen opens, and the step is reported as passed. Observed twice in one run, picking the same wrong element both times, even after
xpathCheckhad already proven a unique locator for the right one.The utility classes surviving while the label is destroyed is exactly backwards for this purpose.
What changed
getText()), whitespace-collapsed vianormalizeInlineTextand capped at 80 characters.toOuterHTML()cleaned throughcleanHtmlSnippet()instead of the upstream simplifier, so nothing nested is discarded.cleanHtmlSnippet()is a new export insrc/utils/html.ts:parseFragment→ the existingcleanAllElements→serialize. It reuses the project's single class-filter policy (TAILWIND_CLASS_PATTERNS, digit classes, attribute whitelist) rather than adding a fourth copy of that chain.cleanElement:.filter(Boolean)after the class split, so a whitespace-onlyclass=" "drops out instead of surviving asclass=" ".formatElementList()replaces the two near-identical map expressions that were drifting between the model-facing prompt and the failure message shown to the Tester.Result
badge-type manualsurvives because it says something about which button this is;inline-flex items-center gap-3 w-fulldoes not.Tests
tests/unit/matched-elements.test.ts— 5 tests: label present when the markup would otherwise be stripped, whitespace collapse, the 80-character cap, utility classes dropped while meaningful ones survive, and the fallback when the error carries no elements.Full unit suite: 1125 pass, 0 fail —
cleanElementis shared, so that was the check that mattered.An upstream fix for
simplifyHtmlElementerasing an element's accessible name is being raised separately against CodeceptJS; this change does not depend on it.🤖 Generated with Claude Code
https://claude.ai/code/session_01JbhzmY1M51pyRysUx32MdP