///<summary> /// Find first element by id ///</summary> public T FindById <T>(string id) { Wait.Milliseconds(Timeouts.Search); var condition = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlTypeDictionary.GetControlType <T>()), new PropertyCondition(AutomationElement.AutomationIdProperty, id) ); var element = RootElement.FindFirst(SearchScope, condition); return(element != null ? (T)Activator.CreateInstance(typeof(T), element) : throw new ElementNotFoundException($"\"{typeof(T).Name}\" with id: \"{id}\" not found")); }
///<summary> /// Find all elements ///</summary> public List <T> FindAll <T>() { Wait.Milliseconds(Timeouts.Search); var condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlTypeDictionary.GetControlType <T>()); var collection = RootElement.FindAll(SearchScope, condition); List <T> elements = new List <T>(); foreach (var element in collection) { elements.Add((T)Activator.CreateInstance(typeof(T), element)); } return(elements.Count != 0 ? elements : throw new ElementNotFoundException($"\"{typeof(T).Name}\" not found")); }
///<summary> /// Find first element by name that contains string ///</summary> public T FindByName <T>(string name) { Wait.Milliseconds(Timeouts.Search); AutomationElement automationElement = RootElement; var result = FindFirstDescendant(automationElement, element => element.Current.ControlType.Equals(ControlTypeDictionary.GetControlType <T>()) && element.Current.Name.Contains(name)); return(result != null ? (T)Activator.CreateInstance(typeof(T), result) : throw new ElementNotFoundException($"\"{typeof(T).Name}\" with name: \"{name}\" not found")); }