public virtual AutomationElement FindWindow(string title, int processId) { List <AutomationSearchCondition> windowSearchConditions = new AutomationSearchConditionFactory().GetWindowSearchConditions(processId); foreach (var searchCondition in windowSearchConditions) { AutomationElement windowElement = Child(searchCondition.OfName(title)); if (windowElement != null) { return(windowElement); } } return(Child(0, new[] { AutomationSearchCondition.GetWindowWithTitleBarSearchCondition(processId), AutomationSearchCondition.ByControlType(ControlType.TitleBar).OfName(title) })); }