protected static AutomationElement FindUIItem(Condition condition, TreeScope treeScope, UIItem scope = null, int timeout = 0) { scope = scope ?? WorkSpace.MainWindow.Window; Report.Output(Report.Level.Debug, Resources.UIItemFindUsingConditionMsg, condition.ToString(), typeof(T).ToString(), treeScope.ToString(), scope.PrimaryIdentification); return(WaitForAE(() => scope.AutomationElement.FindFirst(treeScope, condition), timeout)); }
/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- public virtual void AddEventHandler(AutomationEvent eventId, string eventName, AutomationElement element, TreeScope treeScope) { if (eventName == null) { throw new ArgumentException(); } base.AddEventHandler(); Comment("Adding AddAutomationEventHandler({0}, [{1}], TreeScope.{2}) Control Path = {3}", eventId.ProgrammaticName, Library.GetUISpyLook(element), treeScope.ToString(), Helpers.GetXmlPathFromAutomationElement(element)); handler = new AutomationEventHandler(OnEvent); Automation.AddAutomationEventHandler(eventId, element, treeScope, handler); }
protected void GetAutomationElements(TreeScope scope) { if (!this.CheckControl(this)) { return; } // 20120823 foreach (AutomationElement inputObject in this.InputObject) { System.Collections.Generic.List<AutomationElement > searchResults = new System.Collections.Generic.List<AutomationElement > (); AutomationElementCollection temporaryResults = null; AutomationElement[] outResult; if (scope == TreeScope.Children || scope == TreeScope.Descendants) { WriteVerbose(this, "selected TreeScope." + scope.ToString()); AndCondition[] conditions = getControlsConditions(this); if (conditions != null && conditions.Length > 0) { WriteVerbose(this, "conditions number: " + conditions.Length.ToString()); for (int i = 0; i < conditions.Length; i++) { if (conditions[i] != null) { WriteVerbose(this, conditions[i].GetConditions()); temporaryResults = // 20120823 //this.InputObject.FindAll(scope, inputObject.FindAll(scope, conditions[i]); if (temporaryResults.Count > 0) { foreach (AutomationElement element in temporaryResults) { searchResults.Add(element); } } } } } else { WriteVerbose(this, "no conditions. Performing search with TrueCondition"); temporaryResults = // 20120823 //this.InputObject.FindAll(scope, inputObject.FindAll(scope, Condition.TrueCondition); if (temporaryResults.Count > 0) { WriteVerbose(this, "returned " + temporaryResults.Count.ToString() + " results"); foreach (AutomationElement element in temporaryResults) { searchResults.Add(element); } } } WriteVerbose(this, "results found: " + searchResults.Count.ToString()); WriteObject(this, searchResults.ToArray()); } // if (scope == TreeScope.Children || //scope == TreeScope.Descendants) if (scope == TreeScope.Parent || scope == TreeScope.Ancestors) { outResult = // 20120823 //UIAHelper.GetParentOrAncestor(this.InputObject, scope); UIAHelper.GetParentOrAncestor(inputObject, scope); WriteObject(this, outResult); } } // 20120823 }
/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- public void AddEventHandler(AutomationElement element, TreeScope treeScope, AutomationProperty[] properties) { base.AddEventHandler(); StringBuilder sb = new StringBuilder("["); string divider = ", "; foreach (AutomationProperty prop in properties) { sb.Append(prop.ProgrammaticName); sb.Append(divider); } if (sb.Length > 0) { sb.Remove(sb.Length - divider.Length, divider.Length).Append("]"); } Comment("Adding AddAutomationPropertyChangedEventHandler({0}, TreeScope.{1}, {2}) ControlPath = {3}", Library.GetUISpyLook(element), treeScope.ToString(), sb.ToString(), Helpers.GetXmlPathFromAutomationElement(element)); handler = new AutomationPropertyChangedEventHandler(OnEvent); Automation.AddAutomationPropertyChangedEventHandler(element, treeScope, handler, properties); }
/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- public void AddEventHandler(AutomationElement element, TreeScope treeScope, AutomationProperty[] properties) { base.AddEventHandler(); StringBuilder sb = new StringBuilder("["); string divider = ", "; foreach (AutomationProperty prop in properties) { sb.Append(prop.ProgrammaticName); sb.Append(divider); } if (sb.Length > 0) { sb.Remove(sb.Length - divider.Length, divider.Length).Append("]"); } Comment("Adding AddAutomationPropertyChangedEventHandler({0}, TreeScope.{1}, {2}) ControlPath = {3}", Library.GetUISpyLook(element), treeScope.ToString(), sb.ToString(), Helpers.GetXmlPathFromAutomationElement(element)); handler = new AutomationPropertyChangedEventHandler(OnEvent); Automation.AddAutomationPropertyChangedEventHandler(element, treeScope, handler, properties); }
/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- public virtual void AddEventHandler(AutomationEvent eventId, string eventName, AutomationElement element, TreeScope treeScope) { if (eventName == null) throw new ArgumentException(); base.AddEventHandler(); Comment("Adding AddAutomationEventHandler({0}, [{1}], TreeScope.{2}) Control Path = {3}", eventId.ProgrammaticName, Library.GetUISpyLook(element), treeScope.ToString(), Helpers.GetXmlPathFromAutomationElement(element)); handler = new AutomationEventHandler(OnEvent); Automation.AddAutomationEventHandler(eventId, element, treeScope, handler); }