예제 #1
0
        public ATS GetMatchedElements(string TreeScope = null, string Name = null, string AutomationId = null, string ClassName = null, string FrameworkId = null, string ControlType = null, string Index = null, string SelectNum = AT.SelectNum.Single)
        {
            List <AT> eleList = new List <AT>();

            foreach (AT item in GetATCollection())
            {
                try
                {
                    if (ATElement.IsElementsMatch(atObj: item, Name: Name, ClassName: ClassName, AutomationId: AutomationId))
                    {
                        item.GetElement(TreeScope: TreeScope, Name: Name, AutomationId: AutomationId, ClassName: ClassName, FrameworkId: FrameworkId, ControlType: ControlType);
                        eleList.Add(item);
                        if (SelectNum.Equals(AT.SelectNum.Single))
                        {
                            break;
                        }
                    }
                }
                catch (Exception) { }
            }
            if (eleList.Count == 0)
            {
                throw new Exception("There is no any item matching.");
            }
            AT[] arrAutomationElement = eleList.ToArray();
            return(new ATS(arrAutomationElement));
        }
예제 #2
0
파일: AT.cs 프로젝트: LuffyAutomation/UIA
 private AT GetElementHandle()
 {
     try
     {
         AutomationElement           resultEle  = null;
         AutomationElementCollection resultEles = null;
         AT atObj;
         if (AT.Ele.treeScope.ToString().Equals(AT.TreeScope.Element))
         {
             resultEle = AT.Ele.me;
         }
         else
         {
             if (this.ContainsAndOrWildcard(AT.Ele.Name) || this.ContainsAndOrWildcard(AT.Ele.ClassName) || this.ContainsAndOrWildcard(AT.Ele.AutomationId) || !String.IsNullOrEmpty(AT.Ele.Index))
             {
                 if (AT.Ele.condition == null)
                 {
                     AT.Ele.condition = System.Windows.Automation.Condition.TrueCondition;
                 }
                 resultEles = AT.Ele.me.FindAll(AT.Ele.treeScope, AT.Ele.condition);
             }
             else
             {
                 if (AT.Ele.condition == null)
                 {
                     return(new AT(null));
                 }
                 resultEle = AT.Ele.me.FindFirst(AT.Ele.treeScope, AT.Ele.condition);
             }
             if (resultEle == null)
             {
                 if (!String.IsNullOrEmpty(AT.Ele.Index))
                 {
                     resultEle = resultEles[Convert.ToInt16(AT.Ele.Index)];
                 }
                 else if (resultEles == null)
                 {
                     throw new Exception("Can not find the element.");
                 }
                 else
                 {
                     foreach (AutomationElement item in resultEles)
                     {
                         if (ATElement.IsElementsMatch(atObj: new AT(item), Name: AT.Ele.Name, ClassName: AT.Ele.ClassName, AutomationId: AT.Ele.AutomationId))
                         {
                             return(new AT(item));
                         }
                     }
                 }
             }
         }
         atObj = new AT(resultEle);
         if (resultEle != null && IsElementsMatch(atObj: atObj, Name: AT.Ele.Name, ClassName: AT.Ele.ClassName, AutomationId: AT.Ele.AutomationId))
         {
             return(atObj);
         }
         throw new Exception("");
     }
     catch (Exception)
     {
         throw;
     }
 }