Using Windows.Automation, can I find the AutomationElement element by regex?

I have an object tree that has row objects inside the table parent. I am trying to put all these lines in an AutomationElementCollection

 AutomationElementCollection asdf = ParentTableObj.FindAll ( TreeScope.Children, new PropertyCondition ( AutomationElement.NameProperty, "I want to use regex here" ) ); 

All lines of ' AutomationElement.NameProperty contain the string "row". However, they are variants of this line - for example, "Row1", "Row2", "TopRow", ...

It seems that I can miss something, since the FindAll method allows you to define a TreeScope and find any AutomationElement that matches the provided Condition parameter. I just want my condition to be unlimited, since I can already control the TreeScope search TreeScope .

+1
source share
2 answers
 //Example : AutomationElement element = FindFirstDescendant( AutomationElement.FromHandle(windows_hWnd), (ele)=>Regex.IsMatch( ele.Current.Name, pattern) ); //The generic method to find a descendant element: public static AutomationElement FindFirstDescendant(AutomationElement element, Func<AutomationElement, bool> condition) { var walker = TreeWalker.ControlViewWalker; element = walker.GetFirstChild(element); while (element != null) { if (condition(element)) return element; var subElement = FindFirstDescendant(element, condition); if (subElement != null) return subElement; element = walker.GetNextSibling(element); } return null; } 
+3
source

As indicated in the documentation , you can request a case insensitive comparison. The "regular expression" flag is missing. You will have to perform manual filtering.

+3
source

All Articles