/// <summary> /// Returns the control's direct children automation ids. /// </summary> /// <param name="control"></param> /// <returns>A list of all automation id. It may be empty.</returns> /// <exception cref="InvalidOperationException">Cannot retrieve the automation element.</exception> public static List <string> GetChildrenAutomationIds(this WpfControl control) { UITestControlCollection collection = control.GetChildren(); List <string> ids = collection.Select (c => { var automationElement = c.NativeElement as AutomationElement; if (automationElement == null) { throw new InvalidOperationException("Cannot retrieve the automation element."); } return(automationElement.Current.AutomationId); }).ToList(); return(ids); }
public void PrintingMatchingControlsName() { ApplicationUnderTest.Launch(@"C:\Windows\System32\calc.exe"); //For WinWindow WinWindow calWindow = new WinWindow(); calWindow.SearchProperties[WinWindow.PropertyNames.Name] = "Calculator"; calWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = "CalcFrame"; WinButton button = new WinButton(calWindow); UITestControlCollection buttonColl = button.FindMatchingControls(); var Controls = buttonColl.Select(bu => bu.Name); foreach (var item in Controls) { Console.WriteLine(item); } }