Due to the problems described in this thread: http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/thread/df34a3d0-b81e-4b86-a9ec-b8eb2ab77b7f
I've had to start relying on the TreeWalker class rather than FindFirst/FindAll to obtain AutomationElements for certain controls in our application. However, I've found that when TreeWalker is instantiated using certain PropertyCondition objects, it seems to cause calls to GetNextSibling to lock up my test app's automation thread.
For example, say I want to find a control with a particular AutomationID as a child of a particular parent control. I might use a method like this one:
I sometimes (but not always) see one or more debug messages pop up in the Visual Studio output window that say:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in UIAutomationClientsideProviders.dll
but other than thay I get no indication of what's gone wrong, and the call to GetNextSibling never returns.
Jesse Kindwall
I've had to start relying on the TreeWalker class rather than FindFirst/FindAll to obtain AutomationElements for certain controls in our application. However, I've found that when TreeWalker is instantiated using certain PropertyCondition objects, it seems to cause calls to GetNextSibling to lock up my test app's automation thread.
For example, say I want to find a control with a particular AutomationID as a child of a particular parent control. I might use a method like this one:
public AutomationElement[] GetChildrenByAutomationId(AutomationElement parent, string autoId)
{
PropertyCondition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, autoId);
TreeWalker tw = new TreeWalker(cond);
AutomationElement[] children = new AutomationElement[] { };
AutomationElement child = tw.GetFirstChild(parent);
while (child != null)
{
children = children.Concat(new AutomationElement[] { child }).ToArray();
child = tw.GetNextSibling(child);
}
return children;
}
In this case, the initial call to tw.GetFirstChild returns successfully, however during the first pass through the while loop, execution hangs at the call to tw.GetNextSibling.I sometimes (but not always) see one or more debug messages pop up in the Visual Studio output window that say:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in UIAutomationClientsideProviders.dll
but other than thay I get no indication of what's gone wrong, and the call to GetNextSibling never returns.
Jesse Kindwall