diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md
index d5038a4d4..afc253137 100644
--- a/COMPATIBILITY.md
+++ b/COMPATIBILITY.md
@@ -761,7 +761,7 @@ The snapshot leaves out a checkbox's or radio's value, which `inputValue` still
The page script reads the text selected inside the focused input, textarea, or `contenteditable` host into `SemanticNode.Selection`, as upstream does. A caret, an unfocused field, and a secure field have none. The agent snapshot lists it as `selection="..."` after the field's value, verbatim and escaped (a lone space counts, an empty selection does not), as upstream does. The runner drops it from a field whose value or text holds a registered secret, and from a field cut at its length limit when the selection is not in the part shown. Differences: the port's `press` has no `times`, so one call presses the key once; and the snapshot shows a `value` as it is, a newline included, where upstream escapes it.
-Upstream leaves an `aria-hidden` subtree out of its tree walk, and its text and visibility reads go through Playwright. Here every locator read comes from the tree, so the port lists the subtree and marks each node `AriaHidden` (.NET-only), and role queries and the agent skip those nodes. They are not hidden: a painted `aria-hidden` node is visible to `isVisible`, `toBeVisible`, and `toBeHidden`, as upstream, and a `visible` query keeps it. An action on one is not refused as hidden. A box with no size is not hidden here, since role queries skip hidden nodes and an empty landmark has no size. A hidden node reads its DOM text (`textContent`) instead of `innerText`, so a text query still finds a `visibility: hidden` copy.
+Upstream leaves an `aria-hidden` subtree out of its tree walk, and its text and visibility reads go through Playwright. Here every locator read comes from the tree, so the port lists the subtree and marks each node `AriaHidden` (.NET-only), and role queries and the agent skip those nodes. They are not hidden: a painted `aria-hidden` node is visible to `isVisible`, `toBeVisible`, and `toBeHidden`, as upstream, and a `visible` query keeps it. An action on one is not refused as hidden. A box with no size is not hidden here, since role queries skip hidden nodes and an empty landmark has no size; `isVisible`, `toBeVisible`, `toBeHidden`, `WaitFor`, and the `visible` option read `NodeStates.EmptyBox` too (`LocatorEngine.IsNodeVisible`, .NET-only, web only), so an element with an empty box is not visible, as upstream. A node with no layout box (`display: contents`) and an `option` keep their hidden state. `NodeStates.Mixed` and `NodeStates.ExpandedAbsent` (.NET-only, web only) stand for upstream's nullable states: a role query for `Checked` or `Pressed` skips a mixed node (an indeterminate checkbox, `aria-pressed="mixed"`), and `Expanded = false` skips a node with no `aria-expanded`. `Level` of a `role="heading"` element is its `aria-level`, else 2. A hidden node reads its DOM text (`textContent`) instead of `innerText`, so a text query still finds a `visibility: hidden` copy.
Password fields and `autocomplete=current-password` fields are marked secure. Their values, and their `value` attribute, are omitted from the snapshot. A text, value, or attribute expectation on a secure field fails with `POLICY_DENIED`, as upstream. So do the `textContent`, `inputValue`, `allTextContents`, and `getAttribute` reads (for any attribute).
diff --git a/docs-site/src/content/docs/api/E2E.Engine/NodeStates.md b/docs-site/src/content/docs/api/E2E.Engine/NodeStates.md
index 4b2ef88df..fc278ed42 100644
--- a/docs-site/src/content/docs/api/E2E.Engine/NodeStates.md
+++ b/docs-site/src/content/docs/api/E2E.Engine/NodeStates.md
@@ -66,6 +66,21 @@ public bool Disabled { get; init; }
```
+**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
+
+
+
+
+### EmptyBox
+
+
+```csharp
+public bool EmptyBox { get; init; }
+```
+
+
+The node renders a box with no width or no height. It is not visible, though role queries and the agent still read it (.NET-only; upstream puts this in its `hidden` state). Web only.
+
**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
@@ -79,6 +94,21 @@ public bool Expanded { get; init; }
```
+**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
+
+
+
+
+### ExpandedAbsent
+
+
+```csharp
+public bool ExpandedAbsent { get; init; }
+```
+
+
+The node has no `aria-expanded` of true or false. A role query for `Expanded = false` skips it. Web only (.NET-only; upstream reads the state as nullable).
+
**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
@@ -109,6 +139,21 @@ The node does not render: `display: none`, `visibility`, skipped content, a clos
**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
+
+
+
+### Mixed
+
+
+```csharp
+public bool Mixed { get; init; }
+```
+
+
+The node is a checkbox or a button in the mixed state. A role query for `Checked` or `Pressed` of either value skips it. Web only (.NET-only; upstream reads the state as nullable).
+
+**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
+
diff --git a/src/E2E/Engine/Observation.cs b/src/E2E/Engine/Observation.cs
index 7cec82430..771e335c6 100644
--- a/src/E2E/Engine/Observation.cs
+++ b/src/E2E/Engine/Observation.cs
@@ -23,6 +23,15 @@ public sealed class NodeStates
public bool Expanded { get; init; }
+ /// The node has no aria-expanded of true or false. A role query for Expanded = false skips it. Web only (.NET-only; upstream reads the state as nullable).
+ public bool ExpandedAbsent { get; init; }
+
+ /// The node is a checkbox or a button in the mixed state. A role query for Checked or Pressed of either value skips it. Web only (.NET-only; upstream reads the state as nullable).
+ public bool Mixed { get; init; }
+
+ /// The node renders a box with no width or no height. It is not visible, though role queries and the agent still read it (.NET-only; upstream puts this in its hidden state). Web only.
+ public bool EmptyBox { get; init; }
+
public bool Focused { get; init; }
/// The node does not render: display: none, visibility, skipped content, a closed details. This is what isVisible reads.
diff --git a/src/E2E/Engine/PageScript.cs b/src/E2E/Engine/PageScript.cs
index f00e8d880..af40c796d 100644
--- a/src/E2E/Engine/PageScript.cs
+++ b/src/E2E/Engine/PageScript.cs
@@ -664,6 +664,18 @@ internal static class PageScript
if (el instanceof HTMLInputElement && (el.type === "checkbox" || el.type === "radio")) return el.checked;
return el.getAttribute("aria-checked") === "true";
};
+ // The mixed state of a checkbox (indeterminate, or aria-checked) or a
+ // button (aria-pressed): a role query for either value skips it.
+ const mixedOf = (el) => el instanceof HTMLInputElement && el.type === "checkbox"
+ ? el.indeterminate
+ : el.getAttribute("aria-checked") === "mixed" || el.getAttribute("aria-pressed") === "mixed";
+ // aria-level wins; an h1 to h6 reads its tag; any other heading is level 2 (HTML-AAM).
+ const levelOf = (el, role) => {
+ const tagLevel = /^H[1-6]$/.test(el.tagName) ? Number(el.tagName.slice(1)) : null;
+ if (role !== "heading") return tagLevel;
+ const ariaLevel = Number.parseInt(el.getAttribute("aria-level") || "", 10);
+ return Number.isInteger(ariaLevel) && ariaLevel > 0 ? ariaLevel : tagLevel ?? 2;
+ };
// A link target as the model reads it: origin and path, without
// userinfo, query, or fragment, which routinely carry tokens. A
// dropped query or fragment leaves "?…" or "#…" behind, so the value
@@ -999,9 +1011,13 @@ internal static class PageScript
testId,
placeholder: el.getAttribute("placeholder"),
inputPurpose: secure ? "password" : null,
- level: /^H[1-6]$/.test(el.tagName) ? Number(el.tagName.slice(1)) : null,
+ level: levelOf(el, role),
disabled: disabledOf(el, role),
checked: checkedOf(el),
+ mixed: mixedOf(el),
+ // A box with no width or height; an option has none while its select is closed.
+ emptyBox: !isHidden && el.tagName !== "OPTION" && (() => { const box = rectOf(el); return box !== null && (box.width <= 0 || box.height <= 0); })(),
+ expandedAbsent: !["true", "false"].includes(el.getAttribute("aria-expanded") || "") && el.tagName !== "DETAILS",
expanded: el.getAttribute("aria-expanded") === "true" || (el.tagName === "DETAILS" && el.open),
selected: el.tagName === "OPTION" ? !!el.selected : (el.getAttribute("aria-selected") || "").toLowerCase() === "true",
pressed: el.getAttribute("aria-pressed") === "true",
diff --git a/src/E2E/Engine/WebEngine.cs b/src/E2E/Engine/WebEngine.cs
index fd1c1ca78..7727c0472 100644
--- a/src/E2E/Engine/WebEngine.cs
+++ b/src/E2E/Engine/WebEngine.cs
@@ -3565,6 +3565,9 @@ private static SemanticNode ToNode(WebNode dto, string testIdAttribute)
Checked = dto.Checked,
Disabled = dto.Disabled,
Expanded = dto.Expanded,
+ ExpandedAbsent = dto.ExpandedAbsent,
+ Mixed = dto.Mixed,
+ EmptyBox = dto.EmptyBox,
Focused = dto.Focused,
Hidden = dto.Hidden,
AriaHidden = dto.AriaHidden,
@@ -3853,6 +3856,12 @@ private sealed class WebNode
public bool Expanded { get; set; }
+ public bool ExpandedAbsent { get; set; }
+
+ public bool Mixed { get; set; }
+
+ public bool EmptyBox { get; set; }
+
public bool Selected { get; set; }
public bool Pressed { get; set; }
diff --git a/src/E2E/Expect/Expect.cs b/src/E2E/Expect/Expect.cs
index 8029a8382..6169938ba 100644
--- a/src/E2E/Expect/Expect.cs
+++ b/src/E2E/Expect/Expect.cs
@@ -263,7 +263,7 @@ private Task VisibilityAsync(string matcher, bool visible, TimeSpan? timeout, Ca
return Verdict.Strict(matches.Count);
}
- var shown = matches.Count == 1 && !matches[0].States.Hidden;
+ var shown = matches.Count == 1 && LocatorEngine.IsNodeVisible(matches[0]);
var observed = matches.Count switch
{
0 => "absent",
diff --git a/src/E2E/Locator/LocatorEngine.cs b/src/E2E/Locator/LocatorEngine.cs
index 2c8538a7a..9b09078ec 100644
--- a/src/E2E/Locator/LocatorEngine.cs
+++ b/src/E2E/Locator/LocatorEngine.cs
@@ -103,7 +103,8 @@ internal sealed class LocatorEngine(LocatorEngineOptions options)
internal bool LocatesInEngine => options.Locate is not null;
/// Canonical visibility predicate over a semantic node snapshot (upstream's isNodeVisible).
- internal static bool IsNodeVisible(SemanticNode? node) => node is { States.Hidden: false };
+ internal static bool IsNodeVisible(SemanticNode? node) =>
+ node is { States: { Hidden: false, EmptyBox: false } };
///
/// Denies reading a value, text, or attribute when any node is a secure field: the engine withholds them there, so what reads as
@@ -294,7 +295,7 @@ internal async Task> ResolveOnceAsync(LocatorExpress
// An engine answers `visible` inside scopes, filters, and indices, where only it can. A direct query is held to the same
// predicate here, so it never resolves to a node its own state calls hidden.
- return expression.Visible && expression.Kind is not ("filter" or "index" or "selector") ? nodes.Where(node => !node.States.Hidden).ToList() : nodes;
+ return expression.Visible && expression.Kind is not ("filter" or "index" or "selector") ? nodes.Where(node => IsNodeVisible(node)).ToList() : nodes;
}
catch (EngineException ex) when (retried is not null && !token.IsCancellationRequested && reads.CutOff(ex))
{
diff --git a/src/E2E/Locator/Screen.cs b/src/E2E/Locator/Screen.cs
index 9f6d76cd6..0c9116b58 100644
--- a/src/E2E/Locator/Screen.cs
+++ b/src/E2E/Locator/Screen.cs
@@ -343,7 +343,7 @@ TestException NotVisible(Exception? cause)
}
sampled = true;
- if (node is { States.Hidden: false })
+ if (LocatorEngine.IsNodeVisible(node))
{
return;
}
@@ -937,12 +937,12 @@ await samples.RecordAsync(_screen.Steps, token, () => Time.PollReadsAsync(new Po
throw await _screen.Engine.AmbiguousAsync(Query, matches.Count, token).ConfigureAwait(false);
}
- samples.Add(matches.Count == 0 ? "absent" : matches[0].States.Hidden ? "hidden" : "visible");
+ samples.Add(matches.Count == 0 ? "absent" : LocatorEngine.IsNodeVisible(matches[0]) ? "visible" : "hidden");
return state switch
{
WaitForState.Attached => matches.Count == 1,
- WaitForState.Visible => matches.Count == 1 && !matches[0].States.Hidden,
- WaitForState.Hidden => matches.Count == 0 || matches[0].States.Hidden,
+ WaitForState.Visible => matches.Count == 1 && LocatorEngine.IsNodeVisible(matches[0]),
+ WaitForState.Hidden => matches.Count == 0 || !LocatorEngine.IsNodeVisible(matches[0]),
_ => matches.Count == 0,
};
},
@@ -1593,7 +1593,7 @@ private static EngineException UnsupportedDisplayValue() =>
private static bool Matches(SemanticNode node, LocatorExpression query, bool includeHidden)
{
- if (query.Visible && node.States.Hidden)
+ if (query.Visible && !LocatorEngine.IsNodeVisible(node))
{
return false;
}
@@ -1630,15 +1630,16 @@ private static bool RoleMatches(SemanticNode node, LocatorExpression query, bool
}
var states = node.States;
- return StateIs(query.Checked, states.Checked)
+ return StateIs(query.Checked, states.Checked, states.Mixed)
&& StateIs(query.Disabled, states.Disabled)
&& StateIs(query.Selected, states.Selected)
- && StateIs(query.Expanded, states.Expanded)
- && StateIs(query.Pressed, states.Pressed)
+ && StateIs(query.Expanded, states.Expanded, states.ExpandedAbsent)
+ && StateIs(query.Pressed, states.Pressed, states.Mixed)
&& (query.Level is null || node.Level == query.Level);
}
- private static bool StateIs(bool? wanted, bool actual) => wanted is null || wanted.Value == actual;
+ /// A state with no value to match (mixed, or an attribute that is absent) matches neither true nor false, as Playwright's role selector reads it.
+ private static bool StateIs(bool? wanted, bool actual, bool unset = false) => wanted is null || (!unset && wanted.Value == actual);
///
/// Whether the node's own name, text, or value, or a descendant's, contains the text, ignoring case.
diff --git a/tests/E2E.NUnit.Tests/LocatorIsVisible/LocatorIsVisibleTests.cs b/tests/E2E.NUnit.Tests/LocatorIsVisible/LocatorIsVisibleTests.cs
index 27d842023..653df7e02 100644
--- a/tests/E2E.NUnit.Tests/LocatorIsVisible/LocatorIsVisibleTests.cs
+++ b/tests/E2E.NUnit.Tests/LocatorIsVisible/LocatorIsVisibleTests.cs
@@ -14,25 +14,21 @@ namespace E2E.NUnit.Tests.LocatorIsVisible;
///
public sealed class LocatorIsVisibleTests : PlaywrightTest
{
- // Known difference, hardkoded/e2e-dotnet#1075: an element with an empty box reads as visible.
[Test]
public async Task IsVisible_and_isHidden_should_work()
{
- await ExpectedToFailAsync("Expected False, but was True", async () =>
- {
- await Browser.GotoAsync(Content("
Hi
"));
+ await Browser.GotoAsync(Content("
Hi
"));
- var div = Browser.Locator("div");
- Equal(true, await div.IsVisibleAsync());
- Equal(false, await div.IsHiddenAsync());
+ var div = Browser.Locator("div");
+ Equal(true, await div.IsVisibleAsync());
+ Equal(false, await div.IsHiddenAsync());
- var span = Browser.Locator("span");
- Equal(false, await span.IsVisibleAsync());
- Equal(true, await span.IsHiddenAsync());
+ var span = Browser.Locator("span");
+ Equal(false, await span.IsVisibleAsync());
+ Equal(true, await span.IsHiddenAsync());
- Equal(false, await Browser.Locator("no-such-element").IsVisibleAsync());
- Equal(true, await Browser.Locator("no-such-element").IsHiddenAsync());
- });
+ Equal(false, await Browser.Locator("no-such-element").IsVisibleAsync());
+ Equal(true, await Browser.Locator("no-such-element").IsHiddenAsync());
}
[Test]
@@ -127,38 +123,30 @@ await Browser.GotoAsync(Content("""
}
}
- // Known difference, hardkoded/e2e-dotnet#1075: an element with an empty box reads as visible.
[Test]
public async Task IsVisible_inside_a_button()
{
- await ExpectedToFailAsync("Expected False, but was True", async () =>
- {
- await Browser.GotoAsync(Content(""));
- var span = Browser.Locator("span");
- Equal(false, await span.IsVisibleAsync());
- Equal(true, await span.IsHiddenAsync());
- await Expect.That(span).Not.ToBeVisibleAsync();
- await Expect.That(span).ToBeHiddenAsync();
- await span.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden });
- await Browser.Locator("button").WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Visible });
- });
+ await Browser.GotoAsync(Content(""));
+ var span = Browser.Locator("span");
+ Equal(false, await span.IsVisibleAsync());
+ Equal(true, await span.IsHiddenAsync());
+ await Expect.That(span).Not.ToBeVisibleAsync();
+ await Expect.That(span).ToBeHiddenAsync();
+ await span.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden });
+ await Browser.Locator("button").WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Visible });
}
- // Known difference, hardkoded/e2e-dotnet#1075: an element with an empty box reads as visible.
[Test]
public async Task IsVisible_inside_a_role_button()
{
- await ExpectedToFailAsync("Expected False, but was True", async () =>
- {
- await Browser.GotoAsync(Content("