Retrieve Multiple UIItems ByClassName

2019-09-05 03:30发布

问题:

I have a Custom type, under which I have multiple TextBox controls. the problem is all the TextBox's doesn't have either an Automation Id or the Name. So, I wanted to retrieve all the textboxes in a list, so that, I can operate upon them. I know it's not a good practice to do so but I don't have any other option. The problem is how do I retrieve all the these TextBox's which are under a particular custom type in a List?

If anyone knows a better way around then please suggest.

回答1:

Condition condition = new PropertyCondition(AutomationElement.ClassNameProperty, "customclassname");
AutomationElementCollection TextBoxs = ListThatContainsTextBoxsAutomationElement.FindAll(TreeScope.Children, condition);
 Foreach(AutomationElement TextBox in TextBoxs) 
 {
    //Do something with the TextBoxs
 }