Skip to content

fix: Get Text returns option text instead of value for select elements#4991

Open
mvanhorn wants to merge 1 commit into
MarketSquare:mainfrom
mvanhorn:fix/4953-get-text-select-option
Open

fix: Get Text returns option text instead of value for select elements#4991
mvanhorn wants to merge 1 commit into
MarketSquare:mainfrom
mvanhorn:fix/4953-get-text-select-option

Conversation

@mvanhorn

Copy link
Copy Markdown

What

Restores the pre-v20 behavior of Get Text on a <select> element so it returns the visible option text instead of the selected option's value attribute.

Why

A regression landed between Browser library v19.12.0 and v20.0.0: Get Text on a <select> started returning the selected option's value attribute (e.g. value_1) instead of its visible text (e.g. Berlin). The cause is in node/playwright-wrapper/getters.ts: commit 6b5fe6b expanded the tag check in _getTextContentNoTextType from INPUT/TEXTAREA to also include SELECT, routing selects through locator.inputValue() (the value attribute) instead of innerText().

In v19.12.0 a <select> fell through to innerText(). This PR removes SELECT from the inputValue branch so selects fall through to innerText() again, matching the original behavior. The explicit text_type=inputValue path is unchanged for callers who still want the value attribute.

Changes

  • node/playwright-wrapper/getters.ts: narrow the inputValue branch in _getTextContentNoTextType back to TEXTAREA/INPUT only; update the fallback log message; add a comment documenting the intentional <select> fall-through.
  • node/playwright-wrapper/__tests__/getters.test.ts: update the SELECT no-text-type unit test to expect innerText instead of inputValue.
  • utest/test_get_text.py: add a unit test documenting that select option text is returned unchanged through the keyword wrapper.
  • atest/test/02_Content_Keywords/basic_getters_get_text.robot: update the select acceptance assertions to check the visible option text rather than the value attribute.

Fixes #4953

Get Text on a <select> regressed between v19.12.0 and v20.0.0: it
returned the selected option's value attribute instead of the visible
option text. Commit 6b5fe6b expanded the tag check in
_getTextContentNoTextType to route SELECT through inputValue(); this
restores the v19 behavior by letting <select> fall through to
innerText(). The explicit text_type=inputValue path is unchanged for
callers who still want the value attribute.

Fixes MarketSquare#4953
Comment thread utest/test_get_text.py
assert text == "element text"


def test_get_text_select_returns_option_text(ctx: MagicMock):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this test, it is not needed

logger.info(`Getting text content without text type`);
const tag = await locator.evaluate((e) => e.tagName);
if (tag === 'SELECT' || tag === 'TEXTAREA' || tag === 'INPUT') {
// <select> intentionally falls through to innerText() to restore pre-v20 (v19.12.0) behavior per issue #4953.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove comment, this is documented in tests

@aaltat

aaltat commented Jun 23, 2026

Copy link
Copy Markdown
Member

@allcontributors please add @mvanhorn for code

@allcontributors

Copy link
Copy Markdown
Contributor

@aaltat

I've put up a pull request to add @mvanhorn! 🎉

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.

Get Text Keyword returns value attribute instead of the text of an option element

2 participants