Skip to content

fix(page-controller): match select options by value as well as text - #750

Open
Li-john1021 wants to merge 1 commit into
alibaba:mainfrom
Li-john1021:fix/select-option-match-value
Open

Li-john1021 wants to merge 1 commit into
alibaba:mainfrom
Li-john1021:fix/select-option-match-value

Conversation

@Li-john1021

Copy link
Copy Markdown

What

selectOptionElement previously matched options only via exact textContent. That breaks common cases where option.value differs from the visible label (i18n, codes like apple / international), even though dehydrated DOM already exposes value=... and agents often pass that value.

This change keeps exact textContent first (same behavior as today for ambiguous needles), then falls back to exact option.value. The select_dropdown_option tool description is updated accordingly. Happy-dom regression tests cover text, value/i18n, reject path, and text-first ambiguity.

Closes #749

Related (orthogonal — they change setter/events, not matching): #704, #686, #718.

Type

  • Breaking change
  • Bug fix
  • Feature / Improvement
  • Refactor / Chores
  • Documentation / Website / Demo / Testing

Testing

  • npm run ci passes
  • Tested with happy-dom unit tests (packages/page-controller)
  • Types/doc: tool description + JSDoc wording only
npm test -w @page-agent/page-controller
# 8 passed (4 new in actions.selectOption.test.ts + existing)

Repro before fix: <option value="apple">苹果</option> + selectOptionElement(select, 'apple') → not found. After fix → selects apple.

Requirements / 要求

  • I have read and follow the Code of Conduct and Contributing Guide . / 我已阅读并遵守行为准则。
  • This PR is NOT generated by a bot or AI agent acting autonomously. I have authored or meaningfully reviewed every change. / 此 PR 不是由 bot 或 AI 自主生成的,我已亲自编写或充分审查了每一处变更。

Thank you for reviewing — happy to adjust the match order or wording if you prefer a different approach.

selectOptionElement only compared trimmed textContent, so i18n and
value≠label dropdowns failed when the agent passed the option value
shown in dehydrated DOM (value is in DEFAULT_INCLUDE_ATTRIBUTES).

Prefer exact textContent (unchanged), then fall back to option.value.
Update select_dropdown_option tool copy and add happy-dom coverage.

Fixes alibaba#749
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T03:42:22.377536Z 7c3c6e5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Li-john1021 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c3c6e5448

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// as values while showing localized textContent — agents pass either.
const option =
options.find((opt) => (opt.textContent?.trim() ?? '') === needle) ??
options.find((opt) => opt.value === needle || opt.value === optionText)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check exact option values before trimmed matches

When optionText has surrounding whitespace and a select contains value="foo" before value=" foo " (with unrelated labels), this find accepts the first option via needle before it ever tests the later exact raw value. The advertised exact value selection therefore chooses the wrong option; use separate passes that prefer opt.value === optionText before any trimmed/normalized fallback.

AGENTS.md reference: AGENTS.md:L152-L152

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] selectOptionElement only matches option textContent, not value (breaks i18n / value-based selects)

2 participants