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

后端 未结 2 944
北恋
北恋 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:28

    Instead of trying to find matching controls based on another row, you could use a method that takes the parent (in your case the table) and returns all it's children in a recursive way. It digs all the way down until all available children have been found. It shouldn't matter how much row's your table has, it will try and get all of them. It's usable for any UITestControl.

    public ParentControl GetChildControls(UITestControl parentControl)
    {
        ParentControl parent = new ParentControl();
    
        if (parentControl != null)
        {
            List children = new List();
    
            foreach (UITestControl childControl in parentControl.GetChildren())
            {
                children.Add(GetChildControls(childControl));
            }
    
            parent.Children = new KeyValuePair>(parentControl, children);
        }
    
        return parent;
    }
    

    The parent class

    public class ParentControl
    {
        public KeyValuePair> Children { get; set; }
        public string Value
        {
            get
            {
                return Children.Key.Name;
            }
        }
    }
    

    I just added the Value property for easy access to the name of UITestControl.

提交回复
热议问题