Exemplo n.º 1
0
        //添加好友界面
        AutomationElement FriendMainUI(AutomationElement appElement, string qq)
        {
            AutomationElementCollection item = AutomationElement.RootElement.FindAll(TreeScope.Children,
                                                                                     new PropertyCondition(AutomationElement.ControlTypeProperty, 0xC370));

            appElement = null;
            for (int i = 0; i < item.Count; ++i)
            {
                string name = item[i].Current.Name;
                if (name.Contains(" - 添加好友"))
                {
                    appElement = item[i];
                    break;
                }
            }

            Input.ShowFrame(appElement);
            return(appElement);
        }
Exemplo n.º 2
0
        /// <summary>
        /// resurcive to transfer all automation element in order to buiding a tree.
        /// </summary>
        /// <param name="currentAutoEle"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public IElement Convert(AutomationElement currentAutoEle, IElement parent, Dictionary <string, int> mapUnknowCounter, bool add2Runtime = true)
        {
            //logger.Debug("Start convert...");
            IElement re = DoConvert(currentAutoEle, parent, mapUnknowCounter, add2Runtime);

            //logger.Debug("Finish convert...");
            ShowHiddenElements(currentAutoEle);
            AutomationElementCollection children = currentAutoEle.FindAll(TreeScope.Children, Condition.TrueCondition);

            //logger.Debug("Finish find children...");
            foreach (AutomationElement autoChild in children)
            {
                IElement child = Convert(autoChild, re, mapUnknowCounter, add2Runtime);
                //if (child != null)
                //re.Children.Add(child);
            }
            //logger.Debug("Finish...");
            return(re);
        }
Exemplo n.º 3
0
        //private CaptureElement captureElement = new CaptureElement();

        /// <summary>
        ///
        /// </summary>
        /// <param name="rootAutomationElement"></param>
        /// <returns></returns>
        public List <IElement> Analyzing(
            AutomationElementCollection listRootAutomationElement,
            ElementDiscoverManual elementDiscorerManual)
        {
            //logger.Debug("Start Analyze.....");
            List <IElement> re = new List <IElement>();

            Thread.Sleep(DELAY_INSPECTING_TIME);
            foreach (AutomationElement rootAutoElement in listRootAutomationElement)
            {
                IElement newElement = Analyzing(rootAutoElement, elementDiscorerManual);
                if (newElement != null)
                {
                    re.Add(newElement);
                }
            }
            //logger.Debug("Finish Analyze.....");
            return(re);
        }
Exemplo n.º 4
0
        public static AutomationElement GetIEMenu(AutomationElement ieWindow, out AutomationElement fileMenu)
        {
            if (ieWindow == null)
            {
                HostingHelper.Output(false, "ieWindow cannot be null when checking for menus");
                fileMenu = null;
                return(null);
            }

            AutomationElement ieMenu       = null;
            AutomationElement tempFileMenu = null;

            /* In internet explorer the main menu is not a standard win32 MENU (even though
             * a standard menu is what we get when doing menu merging).  It is instead a
             * "ToolbarWindow32".  Calling GetMenu() on the ie frame will return null. There are
             * 3 "ToolbarWindow32"s by default on windows xp ie6.
             */
            // enumerate all ToolbarWindow32s
            AutomationElementCollection toolbarCollection = ieWindow.FindAll(
                TreeScope.Descendants | TreeScope.Element,
                new PropertyCondition(AutomationElement.ClassNameProperty, "ToolbarWindow32"));

            PropertyCondition fileMenuCondition = new PropertyCondition(
                AutomationElement.AutomationIdProperty, SYSTEM_FILE_MENU);

            if (toolbarCollection != null)
            {
                // find the ToolbarWindow32 that contains the "File" menu.  The file menu is
                // universally (IE and explorer) defined as menu item 32768.
                foreach (AutomationElement el in toolbarCollection)
                {
                    if ((tempFileMenu = el.FindFirst(TreeScope.Descendants | TreeScope.Element, fileMenuCondition)) != null)
                    {
                        ieMenu = el;
                        break;
                    }
                }
            }

            fileMenu = tempFileMenu;
            return(ieMenu);
        }
Exemplo n.º 5
0
        public void PointToElements(Point point)
        {
            AutomationElementCollection aeCollection = null;
            AutomationElement           menuAe       = null;

            using (_generalCacheReq.Activate())
            {
                _element = AutomationElement.FromPoint(point);
                UIAHighlight.HighlightThread_Spy(_element);

                if (_element.Current.ControlType == ControlType.MenuItem)
                {
                    if (UIAUtility.ExpandMenuItem(_element) && _element.FindFirst(TreeScope.Children, _propertyMenuItemCondition) == null)
                    {
                        menuAe = RetrieveMenuElement(_element);
                    }
                }

                if (menuAe == null)
                {
                    if (_element.FindFirst(TreeScope.Children, Condition.TrueCondition) == null)
                    {
                        _element = TreeWalker.ControlViewWalker.GetParent(_element);
                    }
                    aeCollection = _element.FindAll(TreeScope.Children, Condition.TrueCondition);
                }
                else
                {
                    aeCollection = menuAe.FindAll(TreeScope.Descendants, _menuCondition);
                }
                _ancestorElements.Clear();
                _ancestorElements = UIAUtility.GetAutomationElementsLine(_element);
                _childElements.Clear();
                _childElements = aeCollection.Cast <AutomationElement>().ToList();
            }
            Console.WriteLine("childrenelement count {0}, ancestorelement count {1}", _childElements.Count, _ancestorElements.Count);
            if (null != afterPointToElementsEventHander)
            {
                ElementsBuilderEventArgs e = new ElementsBuilderEventArgs(this, _ancestorElements, _childElements, _element);
                afterPointToElementsEventHander(this, e);
            }
        }
Exemplo n.º 6
0
        public AccessHelper(IntPtr hwnd, App app)
        {
            myapp          = app;
            Target         = AutomationElement.FromHandle(hwnd);
            AccessElements = new Dictionary <int, AccessElement>();
            int i = 0;
            AutomationElementCollection elements = Target.FindAll(
                TreeScope.Descendants,
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsInvokePatternAvailableProperty, true),
                    new PropertyCondition(AutomationElement.IsEnabledProperty, true)
                    )
                );

            foreach (AutomationElement element in elements)
            {
                AccessElements.Add(i, new AccessElement(i, element));
                i++;
            }
        }
Exemplo n.º 7
0
        private static System.Windows.Point GetClickablePoint(string iconName)
        {
            IntPtr HWND3 = FindWindowEx(GetDesktopWindow(), (IntPtr)null, "Progman", null);
            IntPtr HWND  = FindWindowEx(HWND3, (IntPtr)null, "SHELLDLL_DefView", null);
            IntPtr HWND2 = FindWindowEx(HWND, (IntPtr)null, "SysListView32", null);

            System.Windows.Point        p   = new System.Windows.Point();
            ControlOp                   co  = new ControlOp(iconName, ControlType.ListItem);
            AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(HWND2));

            foreach (AutomationElement ae in aec)
            {
                if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(iconName))
                {
                    p = ae.GetClickablePoint();
                    return(p);
                }
            }
            return(p);
        }
Exemplo n.º 8
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.º 9
0
        public AutomationElement GetMenuByName(String MenuName, AutomationElement MenuBarElement)
        {
            if (MenuBarElement.Current.ControlType != ControlType.MenuBar)
            {
                return(null);
            }
            MenuName = MenuName.ToUpper();
            AutomationElementCollection aecElementAll = MenuBarElement.FindAll(TreeScope.Children,
                                                                               new PropertyCondition(AutomationElement.IsEnabledProperty, true));

            foreach (AutomationElement aeElement in aecElementAll)
            {
                if (aeElement.Current.Name.ToString().ToUpper().IndexOf(MenuName) >= 0)
                {
                    return(aeElement);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
        void CloseFriendFind(AutomationElement friend)
        {
            AutomationElementCollection items = friend.FindAll(TreeScope.Descendants,
                                                               new PropertyCondition(AutomationElement.ControlTypeProperty, 0xC350));

            for (int i = 0; i < items.Count; ++i)
            {
                LegacyIAccessiblePattern pattern =
                    (LegacyIAccessiblePattern)items[i].GetCurrentPattern(LegacyIAccessiblePattern.Pattern);
                if (pattern != null)
                {
                    if (pattern.Current.Description == "关闭")
                    {
                        Input.ShowFrame(items[i]);
                        Input.Click(items[i], false);
                        return;
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        private static AutomationElement ToggleExtension(IntPtr handle)
        {
            string chromeWindowName = "";

            try
            {
                // find the automation element
                AutomationElement chromeAE = AutomationElement.FromHandle(handle);
                chromeWindowName = chromeAE.Current.Name;
                AutomationElement chromeToolBar = ExtensionsGroup(chromeAE);
                if (chromeToolBar == null)
                {
                    return(null);
                }
                AutomationElementCollection chromeExtentions = Extensions(chromeToolBar);
                AutomationElement           extension        = TooglePluginButton(chromeExtentions);
                return(extension == null ? null : extension);
            }
            catch { return(null); }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Clicks on show details button of a friend in list
        /// </summary>
        public static void AssertClickDetailsInAvatarsView()
        {
            //Select available from combobox
            AutomationElementCollection aeComboItems = StateBasedNavigationPage <TApp> .ComboBoxItems;

            aeComboItems[0].Select();
            Thread.Sleep(2000);
            AutomationElementCollection aeFriendsList = StateBasedNavigationPage <TApp> .AvatarViewFriends;

            //Right click 3rd item in Friends list
            //aeFriendsList[2].SetFocus();
            aeFriendsList[2].Select();
            Thread.Sleep(3000);

            //Find Show Details button and click on it
            AutomationElement aeContactDetails = StateBasedNavigationPage <TApp> .ContactDetails;

            aeContactDetails.Click();
            Thread.Sleep(3000);
        }
Exemplo n.º 13
0
        public static string GetAllItemText()
        {
            IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32768", null);

            if (hWnd != IntPtr.Zero)
            {
                AutomationElementCollection aec = FindByMultipleConditions(AutomationElement.FromHandle(hWnd));
                string itemText = "";
                foreach (AutomationElement ae in aec)
                {
                    itemText = itemText + "," + ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString();
                }
                itemText = itemText.Remove(0, 1);
                return(itemText);
            }
            else
            {
                return("Context not found");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Validations on clicking avatars button
        /// </summary>
        public static void StateBasedNavigation_ClickAvatars()
        {
            //Select available from combobox
            AutomationElementCollection aeComboItems = StateBasedNavigationPage <TApp> .ComboBoxItems;

            aeComboItems[0].Select();
            Thread.Sleep(2000);

            //Find Avatas button and click it
            AutomationElement aeAvatarButton = StateBasedNavigationPage <TApp> .AvatarButton;

            //    aeAvatarButton.SetFocus();
            aeAvatarButton.Select();
            Thread.Sleep(2000);

            //Check that Avatar view is loaded
            AutomationElement aeAvatarsView = StateBasedNavigationPage <TApp> .AvatarView;

            Assert.IsNotNull(aeAvatarsView, "Avatar View is not loaded");
        }
Exemplo n.º 15
0
        private string GetCurrentUrl(AutomationElementCollection toolbars)
        {
            try
            {
                foreach (AutomationElement toolbar in toolbars)
                {
                    var combobox = toolbar.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ComboBox));

                    if (combobox != null)
                    {
                        var edit = combobox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                        return(base.GetUrl(edit.GetCurrentPropertyValue(LegacyIAccessiblePattern.ValueProperty) as string));
                    }
                }
            }
            catch
            { }

            return(null);
        }
Exemplo n.º 16
0
        private static void GetAllWindows(StringBuilder stringBuilder, int level, AutomationElement baseElement)
        {
            string padding         = level == 0 ? string.Empty : Tab;
            var    windowCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
            AutomationElementCollection allWindows = baseElement.FindAll(TreeScope.Children, windowCondition);

            foreach (AutomationElement windowElement in allWindows)
            {
                var    pattern   = (WindowPattern)UIItem.Pattern(windowElement, WindowPattern.Pattern);
                string modalText = pattern == null ? "(null)" : pattern.Current.IsModal.ToString();
                stringBuilder.AppendFormat("{0}Name: {1},  Bounds: {2} ProcessId: {3}, Modal: {4}", padding, windowElement.Current.Name,
                                           windowElement.Current.BoundingRectangle, windowElement.Current.ProcessId, modalText);
                stringBuilder.AppendLine();

                if (level == 0)
                {
                    GetAllWindows(stringBuilder, 1, windowElement);
                }
            }
        }
Exemplo n.º 17
0
        public int Find(int parent, String className, String name, int index)
        {
            AutomationElement baseElement = Find(parent);

            if (baseElement == null)
            {
                return(0);
            }

            AutomationElementCollection elements = baseElement.FindAll(TreeScope.Subtree, CustomConditions.ByName(name));

            if (elements.Count <= index)
            {
                return(0);
            }

            AutomationElement element = elements[index];

            return(element.Current.NativeWindowHandle);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 启动 被测试程序.
        /// </summary>
        public void StartApp()
        {
            Console.WriteLine("尝试启动程序:[{0}]", APP_NAME);
            // 启动被测试的程序
            process = Process.Start(APP_NAME);
            // 当前线程休眠2秒.
            Thread.Sleep(DEFAULT_SLEEP_TIME);
            // 获得对主窗体对象的引用
            testMainForm = AutomationElement.FromHandle(process.MainWindowHandle);
            // 计算器层次下,首先是一个 Pane.
            AutomationElementCollection panes = testMainForm.FindAll(TreeScope.Children,
                                                                     new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));

            // 获取主窗体上的所有按钮.
            testAllButtons = panes[0].FindAll(TreeScope.Children,
                                              new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
            // 获取主窗体上的所有文本框.
            testAllText = panes[0].FindAll(TreeScope.Children,
                                           new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            AutomationElement           target = null;
            AutomationElementCollection automationCollection = AutomationElement.RootElement.FindAll(TreeScope.Children, Condition.TrueCondition);

            foreach (AutomationElement automation in automationCollection)
            {
                if (automation.Current.Name == "MainWindow")// sửa lại thành cửa sổ đang cần spy
                {
                    target = automation;
                    break;
                }
            }
            var automationlist = TestMethod.GetAllDescendants(target);

            foreach (AutomationElement a in automationlist)
            {
                Console.WriteLine(a.Current.AutomationId);
            }
        }
Exemplo n.º 20
0
        public AutomationElement[] GetChildren(IntPtr handle, ControlType controlType, string localizedControlType)
        {
            var window = AutomationElement.FromHandle(handle);

            Condition conditions = new AndCondition
                                   (
                new PropertyCondition(AutomationElement.ControlTypeProperty, controlType),
                new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, localizedControlType)
                                   );

            List <AutomationElement>    children          = new List <AutomationElement>();
            AutomationElementCollection elementCollection = window.FindAll(TreeScope.Descendants, conditions == null ? System.Windows.Automation.Condition.TrueCondition : conditions);

            Thread.Sleep(2000);
            foreach (AutomationElement element in elementCollection)
            {
                children.Add(element);
            }
            return(children.ToArray());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Clicks on show details button of a friend in list
        /// </summary>
        public static void AssertClickDetails()
        {
            //Select available from combobox
            AutomationElementCollection aeComboItems = StateBasedNavigationPage <TApp> .ComboBoxItems;

            aeComboItems[0].Select();
            Thread.Sleep(TIMEWAIT);

            AutomationElementCollection aeFriendsList = StateBasedNavigationPage <TApp> .FriendList;

            // Select 3rd item in Friends list
            aeFriendsList[2].Select();
            Thread.Sleep(TIMEWAIT);

            //Find Show Details button and click on it
            AutomationElement aeContactDetails = StateBasedNavigationPage <TApp> .ContactDetails;

            aeContactDetails.Click();
            Thread.Sleep(TIMEWAIT);
        }
Exemplo n.º 22
0
        private void CheckForControlPattern(object sender, RoutedEventArgs e)
        {
            WaitCallback callback = (state) =>
            {
                AutomationElement windowElt = AutomationElement.FromHandle(_handle);

                // Locate this UserControl with AutomationId
                var ucElt = windowElt.FindFirst(TreeScope.Descendants,
                                                new PropertyCondition(
                                                    AutomationElement.AutomationIdProperty,
                                                    "ID_AutomationClient"));

                // Condition
                PropertyCondition c = new PropertyCondition(AutomationElement.IsControlElementProperty,
                                                            true);
                AutomationElementCollection elements = ucElt.FindAll(TreeScope.Descendants, c);

                StringBuilder sb = new StringBuilder();
                sb.Append("---=== Checking for Control Patterns ===---\n");
                sb.Append("Controls supporting the ScrollPattern:\n");
                foreach (AutomationElement elt in elements)
                {
                    var patterns = from pattern in elt.GetSupportedPatterns()
                                   where pattern.Id == ScrollPattern.Pattern.Id
                                   select pattern.ProgrammaticName;

                    if (patterns.Count() > 0)
                    {
                        sb.Append(elt.Current.ClassName);
                        sb.Append(Environment.NewLine);
                    }
                }

                // Fire on UI thread
                _dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                        new Action <string>(PrintMessage),
                                        sb.ToString());
            };

            ThreadPool.QueueUserWorkItem(callback);
        }
        public void GetMainMenuElements()
        {
            AutomationElement root        = AutomationElement.RootElement;
            AutomationElement smartHMI    = GetMainWindow();
            AutomationElement kcpFrame    = GetElementByAutomationID(smartHMI, "SmartHMI.KcpFrame");
            AutomationElement mainContent = GetElementByAutomationID(kcpFrame, "SmartHMI.MainContent");

            Trace.TraceInformation("mainContent element available");
            AutomationElement overlay = GetElementByAutomationID(mainContent, "Displays.Overlay");

            Trace.TraceInformation("overlay element available");
            AutomationElement mainMenuView = GetElementByAutomationID(overlay, "Views.Menu");

            if (mainMenuView == null)
            {
                Trace.TraceInformation("Main Menu element not available. Not the Main Menu View is shown.");
                return;
            }
            Trace.TraceInformation("Main Menu element available");
            AutomationElement menuViewColumns = GetElementByAutomationID(mainMenuView, "Menu.Columns");

            Trace.TraceInformation("Menu.Columns element available");
            AutomationElement menuView = GetElementByName(menuViewColumns, "KukaRoboter.SmartHMI.UIFramework.Menu.FinderMenuColumn");

            Trace.TraceInformation("MenuView element available");

            List <string> mainMenuButtonNames = new List <string>();
            AutomationElementCollection menuElemetCollection = menuView.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List));

            foreach (AutomationElement item in menuElemetCollection)
            {
                AutomationElementCollection menuButtons = item.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));

                foreach (AutomationElement automationElement in menuButtons)
                {
                    mainMenuButtonNames.Add(string.Format("MainMenu: {0} Button", automationElement.Current.Name.Split('/')[1]));
                }
            }

            ChangeCurrentViewableItems(mainMenuButtonNames);
        }
Exemplo n.º 24
0
 public void LoopElement(AutomationElement ParentElement, TreeNode ParentNode)
 {
     try
     {
         AutomationElementCollection automationElementCollection = ParentElement.FindAll(TreeScope.Children, Condition.TrueCondition);
         IEnumerator enumerator = null;
         try
         {
             enumerator = automationElementCollection.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 AutomationElement  automationElement = (AutomationElement)enumerator.Current;
                 TreeNodeCollection arg_59_0          = ParentNode.Nodes;
                 AutomationElement.AutomationElementInformation current = automationElement.Current;
                 string arg_54_0 = current.Name;
                 string arg_54_1 = " ";
                 current = automationElement.Current;
                 TreeNode treeNode = arg_59_0.Add(arg_54_0 + arg_54_1 + current.LocalizedControlType.ToString());
                 this.dic.Add(treeNode, automationElement);
                 bool flag = automationElement.Equals(this.CurrentElement);
                 if (flag)
                 {
                     this.CurrentNode = treeNode;
                 }
                 this.LoopElement(automationElement, treeNode);
             }
         }
         finally
         {
             if (enumerator is IDisposable)
             {
                 (enumerator as IDisposable).Dispose();
             }
         }
     }
     catch (ElementNotAvailableException expr_BA)
     {
         ProjectData.SetProjectError(expr_BA);
         ProjectData.ClearProjectError();
     }
 }
Exemplo n.º 25
0
        private void Start()
        {
            OrCondition  condition    = new OrCondition(new PropertyCondition(AutomationElement.ClassNameProperty, Shell_TrayWnd), new PropertyCondition(AutomationElement.ClassNameProperty, Shell_SecondaryTrayWnd));
            CacheRequest cacheRequest = new CacheRequest();

            cacheRequest.Add(AutomationElement.NameProperty);
            cacheRequest.Add(AutomationElement.BoundingRectangleProperty);

            bars.Clear();
            children.Clear();
            lasts.Clear();

            using (cacheRequest.Activate())
            {
                AutomationElementCollection lists = desktop.FindAll(TreeScope.Children, condition);
                if (lists == null)
                {
                    Debug.WriteLine("Null values found, aborting");
                    return;
                }
                Debug.WriteLine(lists.Count + " bar(s) detected");
                lasts.Clear();
                foreach (AutomationElement trayWnd in lists)
                {
                    AutomationElement tasklist = trayWnd.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, MSTaskListWClass));
                    if (tasklist == null)
                    {
                        Debug.WriteLine("Null values found, aborting");
                        continue;
                    }
                    Automation.AddAutomationPropertyChangedEventHandler(tasklist, TreeScope.Element, OnUIAutomationEvent, AutomationElement.BoundingRectangleProperty);

                    bars.Add(trayWnd);
                    children.Add(trayWnd, tasklist);
                }
            }

            Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, desktop, TreeScope.Subtree, OnUIAutomationEvent);
            Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, desktop, TreeScope.Subtree, OnUIAutomationEvent);
            loop();
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            // Kill existing instances
            foreach (Process pOld in Process.GetProcessesByName("taskmgr"))
            {
                pOld.Kill();
            }

            // Create a new instance
            Process p = new Process();

            p.StartInfo.FileName       = "taskmgr";
            p.StartInfo.CreateNoWindow = true;
            p.Start();

            Console.WriteLine("Waiting for handle...");

            while (p.MainWindowHandle == IntPtr.Zero)
            {
                ;
            }

            AutomationElement aeDesktop = AutomationElement.RootElement;
            AutomationElement aeForm    = AutomationElement.FromHandle(p.MainWindowHandle);

            Console.WriteLine("Got handle");

            // Get the tabs control
            AutomationElement aeTabs = aeForm.FindFirst(TreeScope.Children,
                                                        new PropertyCondition(AutomationElement.ControlTypeProperty,
                                                                              ControlType.Tab));

            // Get a collection of tab pages
            AutomationElementCollection aeTabItems = aeTabs.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty,
                                                                                                                 ControlType.TabItem));

            // Set focus to the performance tab
            AutomationElement aePerformanceTab = aeTabItems[3];

            aePerformanceTab.SetFocus();
        }
Exemplo n.º 27
0
        public static string GetChromeUrl(IntPtr intPtr)
        {
            if (intPtr == IntPtr.Zero)
            {
                return(null);
            }

            AutomationElement element = AutomationElement.FromHandle(intPtr);

            if (element == null)
            {
                return(null);
            }

            AutomationElementCollection edits5 = element.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
            AutomationElement           edit   = edits5[0];
            string vp = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;

            Console.WriteLine(vp);
            return(vp);
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        private static AutomationElement SkypeTab(IntPtr handle)
        {
            string chromeWindowName = "";

            try
            {
                // find the automation element
                AutomationElement chromeAE = AutomationElement.FromHandle(handle);
                chromeWindowName = chromeAE.Current.Name;
                //situation if chrome process is not foreground, and/or skype tab is not active
                AutomationElement chromeTabControl = TabControl(chromeAE);
                if (chromeTabControl == null)
                {
                    return(null);
                }
                AutomationElementCollection chromeTabItems = TabItems(chromeTabControl);
                AutomationElement           skype          = SkypeTabItem(chromeTabItems);
                return(skype == null ? null : skype);
            }
            catch { return(null); }
        }
Exemplo n.º 29
0
        public AutomationElement GetMenuBar(AutomationElement ApplicationWindowElement)
        {
            try
            {
                AutomationElementCollection aecElementAll = ApplicationWindowElement.FindAll(TreeScope.Children,
                                                                                             new PropertyCondition(AutomationElement.IsEnabledProperty, true));
                foreach (AutomationElement aeElement in aecElementAll)
                {
                    if (aeElement.Current.ControlType == ControlType.MenuBar)
                    {
                        return(aeElement);
                    }
                }

                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 30
0
        public int Find(int parent, int id, int index)
        {
            AutomationElement baseElement = base.Find(parent);

            Condition[] conditions =
            {
                new PropertyCondition(AutomationElement.ControlTypeProperty, controlType),
                new PropertyCondition(AutomationElement.RuntimeIdProperty,   id)
            };

            Condition locator = new AndCondition(conditions);

            AutomationElementCollection elements = baseElement.FindAll(TreeScope.Subtree, locator);

            if (elements.Count <= index)
            {
                return(0);
            }
            logger.Debug(String.Format("Found hwnd: {0}", elements[index].Current.NativeWindowHandle));
            return(elements[index].Current.NativeWindowHandle);
        }