Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public AT Spy()
 {
     try
     {
         AT atObj = null;
         this.me = (this.me == null) ? AutomationElement.RootElement : this.me;  //System.Windows.Automation.Condition.TrueCondition
         AutomationElementCollection t = this.me.FindAll(System.Windows.Automation.TreeScope.Descendants, System.Windows.Automation.Condition.TrueCondition);
         //AutomationElementCollection t = this.me.FindAll(System.Windows.Automation.TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Pane));
         foreach (AutomationElement item in t)
         {
             try
             {
                 Console.WriteLine(string.Format("[{0}] [{1}] [{2}] [{3}]", item.Current.Name.ToString(), item.Current.ControlType.ProgrammaticName.ToString(), item.Current.ClassName.ToString(), item.Current.AutomationId));
             }
             catch (Exception ex)
             {
                 Console.WriteLine(string.Format("[{0}]", ex.Message));
             }
         }
         return(atObj);
     }
     catch (Exception ex)
     {
         throw new Exception("GetElement error. " + ex.Message);
     }
 }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 public void test(AT t)
 {
     try
     {
         AutomationElement aaa = GetTopLevelWindow(t.GetMe());
     }
     catch (Exception ex)
     {
         throw new Exception("GetElementFromHwnd error. " + ex.Message);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 public ScrollEvents(AT elePara)
 {
     this.elePara = elePara;
     try
     {
         scrollPattern = (ScrollPattern)elePara.GetMe().GetCurrentPattern(ScrollPattern.Pattern);
     }
     catch (Exception)
     {
         //throw new Exception("Failed to get scrollable item.");
     }
 }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 public WindowEvents(AT elePara)
 {
     this.elePara = elePara;
     try
     {
         WindowPattern = (WindowPattern)elePara.GetMe().GetCurrentPattern(WindowPattern.Pattern);
     }
     catch (Exception)
     {
         throw new Exception("Failed to get WindowEvents.");
     }
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="atObj"></param>
 public ScrollEvents(AT atObj)
 {
     _elePara = atObj;
     try
     {
         _scrollPattern = (ScrollPattern)atObj.AutomationElement.GetCurrentPattern(ScrollPattern.Pattern);
     }
     catch (Exception)
     {
         //throw new Exception("Failed to get scrollable item.");
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 /// <param name="status"></param>
 /// <returns></returns>
 public CurrentElement GetElementInfo(AT elePara = null, string status = "")
 {
     try
     {
         elePara = elePara == null ? this : elePara;
         //AT eleName = elePara.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString();
         return(new CurrentElement(elePara));
     }
     catch (Exception ex)
     {
         throw new Exception("GetElementInfo error. " + ex.Message);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 public IAccessible(AT elePara)
 {
     this._elePara = elePara;
     try
     {
         var t = (LegacyIAccessiblePattern)elePara.AutomationElement.GetCurrentPattern(LegacyIAccessiblePattern.Pattern);
         _legacyIAccessiblePatternInformation = t.Current;
     }
     catch (Exception)
     {
         throw new Exception("Failed to get IAccessible.");
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool WaitForDisappeared(string timeout = "1")
 {
     try
     {
         AT.WaitProcessEventDelegate += new AT.WaitProcessDelegateHandler(this.EventDo_IsDisappeared);
         AT t = AT.GetElementAndWaitProcess(this, timeout, waitEvent: WaitEvent.Disappeared);
         return(t == null ? true : false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 public static void CloseIE()
 {
     for (int i = 0; i < 3; i++)
     {
         try
         {
             AT IE = new AT().GetElement(ClassName: AT.ClassName.IEFrame);
             IE.DoWindowEvents().Close();
         }
         catch (Exception)
         {
         }
         UtilTime.WaitTime(1);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        public static List <string> GetCoordinateObj()
        {
            Point _Point = new Point();

            _Point.X = Control.MousePosition.X;
            _Point.Y = Control.MousePosition.Y;
            AT            at    = new AT(AutomationElement.FromPoint(_Point));
            ATS           items = at.GetElements(TreeScope: AT.TreeScope.Descendants, ControlType: AT.ControlType.ListItem);
            List <string> list  = new List <string>();

            foreach (AT item in items.GetATCollection())
            {
                list.Add(item.GetElementInfo().Name());
            }
            return(list);
        }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="sender"></param>
 /// <param name="timeout"></param>
 /// <param name="waitEvent"></param>
 /// <param name="interval"></param>
 /// <param name="dateInterval"></param>
 /// <returns></returns>
 public static AT GetElementAndWaitProcess <T>(T sender, string timeout, string waitEvent = WaitEvent.Existed, string interval = "0.5", UtilTime.DateInterval dateInterval = UtilTime.DateInterval.Second)
 {
     try
     {
         DateTime dt = DateTime.Now;
         AT       at = null;
         while (true)
         {
             UtilTime.WaitTime(Convert.ToDouble(interval));
             try
             {
                 at = WaitProcessEventDelegate(sender, new WaitProcessArgs());
                 if (at != null && waitEvent.Equals(WaitEvent.Existed))
                 {
                     UtilTime.WaitTime(Convert.ToDouble(interval));
                     return(at);
                 }
                 else if (at == null && waitEvent.Equals(WaitEvent.Disappeared))
                 {
                     return(null);
                 }
             }
             catch (Exception)
             {
                 throw;
             }
             if (UtilTime.DateDiff(dt, DateTime.Now, dateInterval) > Convert.ToDouble(timeout))
             {
                 throw new Exception(string.Format("Timeout > {0}s.", timeout));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         foreach (Delegate item in WaitProcessEventDelegate.GetInvocationList())
         {
             typeof(AT).GetEvent(nameof(WaitProcessEventDelegate)).RemoveEventHandler(new AT(), item);
             //typeof(AT).GetEvent("WaitProcessEventDelegate").RemoveEventHandler(new AT(), item);
         }
     }
 }
Exemplo n.º 14
0
 public ATS GetElements(string TreeScope = null, string Name = null, string AutomationId = null, string ClassName = null, string FrameworkId = null, string ControlType = null)
 {
     try
     {
         System.Windows.Automation.TreeScope treeScope = GetTreeScope(TreeScope);
         System.Windows.Automation.Condition condition = GetCondition(Name, AutomationId, ClassName, FrameworkId, ControlType);
         me = me == null ? AutomationElement.RootElement : me;
         AutomationElementCollection aec = me.FindAll(treeScope, condition);
         AT[] at = new AT[aec.Count];
         for (int i = 0; i < aec.Count; i++)
         {
             at[i] = new AT(aec[i]);
         }
         return(new ATS(at));
     }
     catch (Exception ex)
     {
         throw new Exception("GetElements error. " + ex.Message);
     }
 }
Exemplo n.º 15
0
 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;
     }
 }
Exemplo n.º 16
0
 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);
     }
 }
Exemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 public CurrentElement(AT elePara)
 {
     this.elePara = elePara;
     this.current = elePara.GetMe().Current;
 }
Exemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="elePara"></param>
 public CurrentElement(AT elePara)
 {
     this.elePara = elePara;
     current      = elePara.AutomationElement.Current;
 }
Exemplo n.º 19
0
 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;
     }
 }