Skip to content

Commit

Permalink
fix: Identify the root (desktop) element by UIA class name, not runti…
Browse files Browse the repository at this point in the history
…me ID (#1048)

On Windows 11 24H2 (GE), the runtime ID of the desktop element changed from
`[2A,10010]` to `[2A,1000C]`, causing live inspect in Accessibility
Insights for Windows to break. This commit switches to identifying the
desktop element by its UIA class name, which has been stable across all
supported Windows versions.

Addresses microsoft/accessibility-insights-windows#1837.
  • Loading branch information
codeofdusk committed Sep 5, 2024
1 parent 573776a commit a4c1ba2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
26 changes: 10 additions & 16 deletions src/Core/Misc/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ namespace Axe.Windows.Core.Misc
public static class ExtensionMethods
{
/// <summary>
/// DesktopElement runtime Id.
/// UIA class name of the root (desktop) element
/// </summary>
const string DesktopElementRuntimeId = "[2A,10010]";
const string DesktopElementClassName = "#32769";

/// <summary>
/// WCOS runtime ID
/// </summary>
const string WCOSElementRuntimeId = "[0,0]";
const string WCOSDesktopElementRuntimeId = "[0,0]";

/// <summary>
/// Get A11yElementData object out of A11yElement
Expand Down Expand Up @@ -638,19 +639,12 @@ public static bool IsOffScreen(this A11yElement e)
/// <returns></returns>
public static bool IsRootElement(this IA11yElement e)
{
// on Desktop, RuntimeId is available with specific ID.
// however on WCOS, the desktop equivalent process is PID 0 and runtime ID is 0,0
return e != null && (e.RuntimeId == DesktopElementRuntimeId || (e.ProcessId == 0 && e.RuntimeId == WCOSElementRuntimeId));
}

/// <summary>
/// Check whether string is matched with DesktopElment runtime Id.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsDesktopElementRuntimeId(string str)
{
return DesktopElementRuntimeId == str;
// On Windows, check for the desktop (root) element by class name.
// On WCOS, check for the desktop by process and runtime IDs.
return e != null && (
e.ClassName == DesktopElementClassName
|| (e.ProcessId == 0 && e.RuntimeId == WCOSDesktopElementRuntimeId)
);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/RulesTest/PropertyConditions/BoolPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void TestIsDesktopTrue()
{
using (var e = new MockA11yElement())
{
var property = new A11yProperty(PropertyType.UIA_RuntimeIdPropertyId, new int[] { 0x2A, 0x10010 });
var property = new A11yProperty(PropertyType.UIA_ClassNamePropertyId, "#32769");
e.Properties.Add(property.Id, property);
Assert.IsTrue(IsDesktop.Matches(e));
} // using
Expand Down Expand Up @@ -159,7 +159,7 @@ public void TestIsNotDesktopFalse()
{
using (var e = new MockA11yElement())
{
var property = new A11yProperty(PropertyType.UIA_RuntimeIdPropertyId, new int[] { 0x2A, 0x10010 });
var property = new A11yProperty(PropertyType.UIA_ClassNamePropertyId, "#32769");
e.Properties.Add(property.Id, property);
Assert.IsFalse(IsNotDesktop.Matches(e));
} // using
Expand Down

0 comments on commit a4c1ba2

Please sign in to comment.