Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeWalker issue in Microsoft Office Picture Manager #97

Open
Descolada opened this issue Jul 20, 2022 · 0 comments
Open

TreeWalker issue in Microsoft Office Picture Manager #97

Descolada opened this issue Jul 20, 2022 · 0 comments

Comments

@Descolada
Copy link

Original post at Q&A: https://docs.microsoft.com/en-us/answers/questions/929263/uiautomation-treewalker-misbehaving-in-microsoft-o.html

After getting a child element inside Picture Manager, using the TreeWalker to walk the UIA tree is behaving erratically.

I am running Windows 10 Pro 10.0.19044, and Microsoft Office 2010 Picture Manager.

How to reproduce (using inspect.exe tool in UI Automation mode):

  1. Open up an image in Picture Manager
  2. Inspect the image element: Inspect tools' TreeWalker "Navigate to Previous sibling" and "Navigate to Next sibling" buttons are unavailable
  3. Inspect the toolbar under the image (where the Next and Previous buttons are): Inspect tools' next and previous sibling buttons are unavailable
  4. Inspect the image element, click on TreeWalker "Parent" button, then click twice on either the "Navigate to First Child" button or the "Navigate to Last Child" button. Now the sibling buttons are available, and clicking through them gets both the image element and the toolbar element.
    Note: using the inspect.exe tool is only a demonstration, the same issue exists using the framework directly.

Expected behaviour:

  1. TreeWalking to previous and next sibling should be available right away.
  2. After getting the parent element, getting the original element shouldn't take two steps.

I tried to create a reproducible sample with C#, but the code freezes altogether. Open up a new Notepad window, and Microsoft Office 2010 Picture Manager window, and open a random image. Using System, System.Windows.Automation, System.Runtime.InteropServices:

 AutomationElement rootElement = AutomationElement.RootElement;
 AutomationElement npEl = rootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Untitled - Notepad"));
 npEl.SetFocus();
 Console.WriteLine("Found and activated Notepad");
 AutomationElement documentEl = npEl.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document));
 Console.WriteLine("Document element name: " + documentEl.Current.Name);
    
 AutomationElement pmEl = rootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Microsoft Office 2010"));
 pmEl.SetFocus();
 Console.WriteLine("Found and activated window");
 AutomationElement imageEl = pmEl.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Image));
 Console.WriteLine("Image element name: " + imageEl.Current.Name);
 Console.ReadLine();

This stops indefinitely at line 11.

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

No branches or pull requests

1 participant