CodedUI “FindMatchingControls()” works 10% of the time but usually returns about half of the controls

后端 未结 2 947
北恋
北恋 2020-12-07 06:18

Problem: I am using FindMatchingControls() to create a Collection of rows in a WPF table. I have written a loop that will set the ComboBox in each row to a

2条回答
  •  佛祖请我去吃肉
    2020-12-07 06:33

    PixelPlex (above) has provided the best answer. All I had to add to PixelPlex's code was an If statement to set the ComboBox to a value when it was found. The foreach is therefore as below in my case ...

                foreach (UITestControl childControl in parentControl.GetChildren())
                {
                    children.Add(GetChildControls(childControl));
    
                    //Added below If statement to set ComboBox selected item to "Carrots"...
                    if (childControl.ClassName == "Uia.ComboBox")
                    {
                        WpfComboBox cb = (WpfComboBox)childControl; 
                        cb.SelectedItem = "Carrots";
                    }
                }
    

    This selects Carrots from my ComboBox... Everything that does not satisfy my If statement is not relevant so I don't do anything with it.

提交回复
热议问题