/// <summary> /// /// </summary> /// <param name="atObj"></param> /// <param name="treeScope"></param> /// <param name="name"></param> /// <param name="automationId"></param> /// <param name="className"></param> /// <param name="frameworkId"></param> /// <param name="controlType"></param> /// <returns></returns> protected static bool IsElementsMatch(AT atObj = null, string name = null, string treeScope = null, string automationId = null, string className = null, string frameworkId = null, string controlType = null) { try { var t = ""; try { t = atObj?.GetElementInfo().Name(); } catch (Exception) { } IsElementMatch(t, name); try { t = atObj?.GetElementInfo().ClassName(); } catch (Exception) { } IsElementMatch(t, className); try { t = atObj?.GetElementInfo().AutomationId(); } catch (Exception) { } IsElementMatch(t, automationId); try { t = atObj?.GetElementInfo().ControlType(); } catch (Exception) { } IsElementMatch(t, controlType); try { t = atObj?.GetElementInfo().FrameworkId(); } catch (Exception) { } IsElementMatch(t, frameworkId); return(true); } catch (Exception) { return(false); } }
/// <summary> /// /// </summary> /// <param name="atObj"></param> /// <param name="TreeScope"></param> /// <param name="Name"></param> /// <param name="AutomationId"></param> /// <param name="ClassName"></param> /// <param name="FrameworkId"></param> /// <param name="ControlType"></param> /// <returns></returns> protected static bool IsElementsMatch(AT atObj = null, string Name = null, string TreeScope = null, string AutomationId = null, string ClassName = null, string FrameworkId = null, string ControlType = null) { try { string t = ""; try { t = atObj.GetElementInfo().Name(); } catch (Exception) { } IsElementMatch(t, Name); try { t = atObj.GetElementInfo().ClassName(); } catch (Exception) { } IsElementMatch(t, ClassName); try { t = atObj.GetElementInfo().AutomationId(); } catch (Exception) { } IsElementMatch(t, AutomationId); try { t = atObj.GetElementInfo().ControlType(); } catch (Exception) { } IsElementMatch(t, ControlType); try { t = atObj.GetElementInfo().FrameworkId(); } catch (Exception) { } IsElementMatch(t, FrameworkId); return(true); } catch (Exception) { return(false); } }
public string SelectItemFromCollection(string strIndex = null, string name = null, string strDoMode = ATElement.SelectMode.Point) { try { AT ele = null; if (!String.IsNullOrEmpty(name)) { try { ele = this.GetMatchedElements(Name: name, TreeScope: AT.TreeScope.Element).GetATCollection()[0]; } catch (Exception ex) { throw new Exception(string.Format("The item {0} does not exist.", name, ex.Message)); } } else { try { ele = this.GetATCollection()[Convert.ToInt16(strIndex)]; } catch (Exception ex) { throw new Exception(string.Format("The item index {0} does not exist", strIndex, ex.Message)); } } ele.DoByMode(strDoMode); string t_name = "Can not get name"; try { t_name = ele.GetElementInfo().Name(); } catch (Exception) { } return(t_name); } catch (Exception) { throw; } }
public AT GetElement(string TreeScope = null, string Name = null, string AutomationId = null, string ClassName = null, string FrameworkId = null, string ControlType = null, string Index = null, string Timeout = null, string IsEnabled = null) { try { AT atObj = null; this.me = (this.me == null) ? AutomationElement.RootElement : this.me; System.Windows.Automation.TreeScope treeScope = GetTreeScope(TreeScope); System.Windows.Automation.Condition condition = GetCondition(Name, AutomationId, ClassName, FrameworkId, ControlType); if (WaitProcessEventDelegate != null && !String.IsNullOrEmpty(Timeout)) { Timeout = null; } AT.Ele.me = me; AT.Ele.condition = condition; AT.Ele.treeScope = treeScope; AT.Ele.Name = Name; AT.Ele.AutomationId = AutomationId; AT.Ele.ClassName = ClassName; AT.Ele.Index = Index; if (String.IsNullOrEmpty(Timeout)) { atObj = this.GetElementHandle(); } else { WaitProcessEventDelegate += new AT.WaitProcessDelegateHandler(EventDo_GetElementTimeout); atObj = GetElementAndWaitProcess(new AT(), Timeout); } if (!String.IsNullOrEmpty(IsEnabled)) { if (!(atObj.GetElementInfo().IsEnabled())) { throw new Exception("Not Enabled. "); } } return(atObj); } catch (Exception ex) { throw new Exception("GetElement error. " + ex.Message); } }