From 0ec00d148b9e4abeb7bb503ff7752fd2b487c44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:48:21 -0300 Subject: [PATCH] Carry attributes on the text nodes of inline elements (Closes #1062) getByText on an inline span read in its parent's line resolved to a bare text node with no attributes, so GetAttributeAsync("id") returned null. The node now carries the element's attributes. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- src/E2E/Engine/PageScript.cs | 3 ++- tests/E2E.Tests/Controls/ControlsTests.cs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/E2E/Engine/PageScript.cs b/src/E2E/Engine/PageScript.cs index 693fd3330..f0506d0e5 100644 --- a/src/E2E/Engine/PageScript.cs +++ b/src/E2E/Engine/PageScript.cs @@ -869,13 +869,14 @@ internal static class PageScript // The inline elements read in the element's line that have no node of // their own, as bare nodes of text under it, so a text query still // finds a word the line carries, as Playwright's text engine does. + // They carry their attributes, so a read of the match finds its id. // They stay out of the tree the agent reads. const inlineNodesOf = (parent, isHidden) => { const out = []; for (const child of renderedChildrenOf(parent)) { if (child.nodeType !== Node.ELEMENT_NODE || !flowsInLine(child) || listed(child, roleOf(child))) continue; const text = cut(lineRunOf(child), Infinity); - if (text) out.push({ ref: stamp(child), text, hidden: isHidden, rect: rectOf(child), children: inlineNodesOf(child, isHidden) }); + if (text) out.push({ ref: stamp(child), text, hidden: isHidden, attributes: attributesOf(child, false), rect: rectOf(child), children: inlineNodesOf(child, isHidden) }); } return out; }; diff --git a/tests/E2E.Tests/Controls/ControlsTests.cs b/tests/E2E.Tests/Controls/ControlsTests.cs index ef99df85d..ca18cf77f 100644 --- a/tests/E2E.Tests/Controls/ControlsTests.cs +++ b/tests/E2E.Tests/Controls/ControlsTests.cs @@ -323,6 +323,13 @@ public Task A_hidden_twin_is_skipped_by_a_visible_query_and_reached_by_index() = Assert.True(await banner.Last().IsVisibleAsync()); }); + [Fact] + public Task A_text_match_inside_a_line_reads_its_own_attributes() => RunAsync(async screen => + { + // The badge span is read in the item's line, so it has no node of its own; its match still answers for it. + Assert.Equal("badge", await screen.GetByText("urgent").First().GetAttributeAsync("class")); + }); + [Fact] public Task Filters_narrow_a_list_by_text_or_a_nested_match_and_nth_picks_one_row() => RunAsync(async screen => {