Ejemplo n.º 1
0
        public static IUIAutomationElement FindDescendantByName(
            this IUIAutomationElement parent,
            string name
            )
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            var condition = Helper.Automation.CreatePropertyCondition(
                AutomationElementIdentifiers.NameProperty.Id,
                name
                );
            var child = Helper.Retry(
                () => parent.FindFirst(TreeScope.TreeScope_Descendants, condition),
                AutomationRetryDelay,
                retryCount: AutomationRetryCount
                );

            if (child == null)
            {
                throw new InvalidOperationException(
                          $"Could not find item with name '{name}' under '{parent.GetNameForExceptionMessage()}'."
                          );
            }

            return(child);
        }
Ejemplo n.º 2
0
        public IUIAutomationElement GetScrollingContainerElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document");

            IUIAutomationCondition conditions   = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   frameElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            conditionArray    = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "mainContent");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListControlTypeId);

            conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement contentElement = frameElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            conditionArray    = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Scrolling Container");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId);
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "group");

            conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement scrollingContainerElement = contentElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(scrollingContainerElement);
        }
Ejemplo n.º 3
0
        public IUIAutomationElement GetBoxFromPane(IUIAutomationElement rootElement, int controlType)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[1];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, controlType);
            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions);

            return(reportElement);
        }
Ejemplo n.º 4
0
        public IUIAutomationElement GetElementFromPane(IUIAutomationElement rootElement, string title)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, title);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_TextControlTypeId);
            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions);

            return(reportElement);
        }
Ejemplo n.º 5
0
        public IUIAutomationElement GetRowOfTabs(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_TabControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "tab");
            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions);

            return(reportElement);
        }
Ejemplo n.º 6
0
        public IUIAutomationElement GetUpdateLinkElement(IUIAutomationElement updateDocumentElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_HyperlinkControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "headerLinkUpdates");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions        = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   updateLinkElement = updateDocumentElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(updateLinkElement);
        }
Ejemplo n.º 7
0
        public IUIAutomationElement GetAppInfoElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions     = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   appInfoElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(appInfoElement);
        }
Ejemplo n.º 8
0
        public IUIAutomationElement GetUpdateDocumentElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "frameHeader");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document");

            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   updateElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(updateElement);
        }
Ejemplo n.º 9
0
        public IUIAutomationElement GetReportElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Report this review");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId);
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpReportReviewMenu");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   reportElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(reportElement);
        }
Ejemplo n.º 10
0
        public IUIAutomationElement GetInstallButtonElement(IUIAutomationElement appInfoElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Install");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpBuyButton");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId);

            IUIAutomationCondition conditions           = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   installButtonElement = appInfoElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(installButtonElement);
        }
Ejemplo n.º 11
0
        public IUIAutomationElement GetTopFreeHome(IUIAutomationElement element)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId);

            IUIAutomationCondition conditions     = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   topFreeElement = element.FindFirst(TreeScope.TreeScope_Subtree, conditions);

            Console.WriteLine(topFreeElement.CurrentName);

            return(topFreeElement);
        }
Ejemplo n.º 12
0
        public IUIAutomationElement GetRootElement(IntPtr storeHwnd)
        {
            //IUIAutomationCacheRequest cacheRequest = automation.CreateCacheRequest();

            IUIAutomationElement storeElement = _automation.ElementFromHandle(storeHwnd);
            //int[] runtimeId = storeElement.GetRuntimeId();
            //for (int i = 0; i < runtimeId.Length; i++)
            //{
            //    Console.WriteLine(runtimeId[i]);
            //}

            IntPtr webPlatformHwnd = NativeMethods.FindWindowEx(storeHwnd, IntPtr.Zero, "Web Platform Embedding", "");

            Console.WriteLine(webPlatformHwnd);

            IntPtr IEServerHwnd = NativeMethods.FindWindowEx(webPlatformHwnd, IntPtr.Zero, "Internet Explorer_Server", "");

            Console.WriteLine(IEServerHwnd);
            // last native window handler
            IUIAutomationElement IEServerElement = _automation.ElementFromHandle(IEServerHwnd);


            IUIAutomationCondition condition1 = _automation.CreatePropertyCondition(
                UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId);
            IUIAutomationCondition condition2 = _automation.CreatePropertyCondition(
                UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions = _automation.CreateAndCondition(condition1, condition2);

            IUIAutomationElement IEElement = IEServerElement.FindFirst(TreeScope.TreeScope_Children, conditions);
            String id = IEElement.CurrentFrameworkId;

            Console.WriteLine(id);

            condition1 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Store");
            condition2 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId);

            conditions = _automation.CreateAndCondition(condition1, condition2);
            IUIAutomationElement storePaneElement = IEElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement rootElement = storePaneElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return(rootElement);
        }
Ejemplo n.º 13
0
        public void GoBack(IUIAutomationElement updateElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Back");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "backButton");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions  = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   backElement = updateElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            this.ClickElement(backElement);
            Thread.Sleep(2000);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Given an <see cref="IUIAutomationElement"/>, returns a descendant with the className specified by <paramref name="className"/>.
        /// Throws an <see cref="InvalidOperationException"/> if no such descendant is found.
        /// </summary>
        public static IUIAutomationElement FindDescendantByClass(this IUIAutomationElement parent, string className)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            var condition = Helper.Automation.CreatePropertyCondition(AutomationElementIdentifiers.ClassNameProperty.Id, className);
            var child     = parent.FindFirst(TreeScope.TreeScope_Descendants, condition);

            if (child == null)
            {
                throw new InvalidOperationException($"Could not find item with class '{className}' under '{parent.GetNameForExceptionMessage()}'.");
            }

            return(child);
        }
        public SetResult TrySet(string value)
        {
            if (!DoesApply())
            {
                return(SetResult.NotApplicable);
            }
            _element.ExpandAll(_automation, 0);

            if (string.IsNullOrWhiteSpace(value))
            {
                DeselectAll(_selectionPattern.GetCurrentSelection());
                return(SetResult.Success);
            }

            var condition = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, value);
            var item      = _element.FindFirst(TreeScope.TreeScope_Descendants, condition);

            return(item == null
                ? SetResult.Failure
                : new SelectionItemPattern(item, _selectionPattern.CurrentCanSelectMultiple != 0).TrySet(SelectionItemPattern
                                                                                                         .SelectValue));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Given an <see cref="IUIAutomationElement"/>, returns a descendent following the <paramref name="path"/>.
        /// Throws an <see cref="InvalidOperationException"/> if no such descendant is found.
        /// </summary>

        public static IUIAutomationElement FindDescendantByPath(this IUIAutomationElement element, string path)
        {
            string[] pathParts = path.Split(".".ToCharArray());

            // traverse the path
            IUIAutomationElement item = element;
            IUIAutomationElement next = null;

            foreach (string pathPart in pathParts)
            {
                next = item.FindFirst(TreeScope.TreeScope_Descendants, Helper.Automation.CreatePropertyCondition(AutomationElementIdentifiers.LocalizedControlTypeProperty.Id, pathPart));

                if (next == null)
                {
                    ThrowUnableToFindChildException(path, item);
                }

                item = next;
            }

            return(item);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Get DesktopElement based on Process Id.
        /// </summary>
        /// <param name="pid"></param>
        /// <returns>return null if fail to get an element by process Id</returns>
        public static DesktopElement ElementFromProcessId(int pid)
        {
            IUIAutomationElement   root      = null;
            DesktopElement         element   = null;
            IUIAutomationCondition condition = null;

            try
            {
                // check whether process exist first.
                // if not, it will throw an ArgumentException
                using (var proc = Process.GetProcessById(pid))
                {
                    root      = UIAutomation.GetRootElement();
                    condition = UIAutomation.CreatePropertyCondition(PropertyType.UIA_ProcessIdPropertyId, pid);
                    var uia = root.FindFirst(TreeScope.TreeScope_Descendants, condition);
                    element = ElementFromUIAElement(uia);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                // report and let it return null
                ex.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types
            finally
            {
                if (root != null)
                {
                    Marshal.ReleaseComObject(root);
                }
                if (condition != null)
                {
                    Marshal.ReleaseComObject(condition);
                }
            }
            return(element);
        }
        /// <summary>
        /// Get DesktopElement based on Process Id.
        /// </summary>
        /// <param name="pid"></param>
        /// <returns>return null if fail to get an element by process Id</returns>
        public static DesktopElement ElementFromProcessId(int pid)
        {
            IUIAutomationElement   root      = null;
            DesktopElement         element   = null;
            IUIAutomationCondition condition = null;

            try
            {
                // check whether process exist first.
                // if not, it will throw an ArgumentException
                using (var proc = Process.GetProcessById(pid))
                {
                    root      = UIAutomation.GetRootElement();
                    condition = UIAutomation.CreatePropertyCondition(PropertyType.UIA_ProcessIdPropertyId, pid);
                    var uia = root.FindFirst(TreeScope.TreeScope_Descendants, condition);
                    element = ElementFromUIAElement(uia);
                }
            }
            catch (Exception ex)
            {
                //silent and let it return null
                Debug.WriteLine(ex);
            }
            finally
            {
                if (root != null)
                {
                    Marshal.ReleaseComObject(root);
                }
                if (condition != null)
                {
                    Marshal.ReleaseComObject(condition);
                }
            }
            return(element);
        }
Ejemplo n.º 19
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (count < 4)
            {
                title = list[count];
                count++;
            }
            else
            {
                count = 0;
                title = list[count];
                count++;
            }
            //找到QQ
            Process[] process = Process.GetProcessesByName("QQ");

            foreach (Process p in process)
            {
                textBox1.Clear();
                //從QQ產生root automation
                IUIAutomationElement _viveportAutomationElement = _automation.ElementFromHandle(
                    p.MainWindowHandle);

                if (_viveportAutomationElement == null)
                {
                    throw new InvalidOperationException("QQ must be running");
                }
                //依據屬性名稱 找出tabbox
                IUIAutomationCondition conditionNote = _automation.CreatePropertyCondition(
                    _propertyIdName, title);

                IUIAutomationElement _tabBoxAutomationElement = _viveportAutomationElement.FindFirst(
                    TreeScope.TreeScope_Descendants,
                    conditionNote);
                if (_tabBoxAutomationElement == null)
                {
                    throw new InvalidOperationException("Could not find " + title);
                }
                //由tab找出按鍵範圍 移動游標點擊
                tagPOINT point = new tagPOINT();
                _tabBoxAutomationElement.GetClickablePoint(out point);
                Cursor.Position = new Point((int)point.x, (int)point.y);
                LeftClick();
                Thread.Sleep(150);
                //找出QQ聊天室顯示框
                conditionNote = _automation.CreatePropertyCondition(
                    _propertyIdName, "消息");

                IUIAutomationElement _resultTextBoxAutomationElement = _viveportAutomationElement.FindFirst(
                    TreeScope.TreeScope_Descendants,
                    conditionNote);

                if (_resultTextBoxAutomationElement == null)
                {
                    throw new InvalidOperationException("Could not find 消息");
                }
                //取出消息
                UIAutomationClient.IUIAutomationLegacyIAccessiblePattern legacyPattern1 = (UIAutomationClient.IUIAutomationLegacyIAccessiblePattern)_resultTextBoxAutomationElement.GetCurrentPattern(patternId);

                //放到texebox
                List <char> list = legacyPattern1.CurrentValue.ToList();
                foreach (char i in list)
                {
                    if (i != '\r')
                    {
                        textBox1.AppendText(i.ToString());
                    }
                    else
                    {
                        textBox1.AppendText(Environment.NewLine);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public void Test1()
        {
            ProcessStartInfo x = new ProcessStartInfo();

            x.FileName = @"C:\Windows\System32\calc.exe";
            var process = Process.Start(x);

            process.WaitForInputIdle();

            var ROOT = new CUIAutomationClass().GetRootElement();

            var prc = ROOT.FindAll(TreeScope.TreeScope_Children, new CUIAutomationClass().CreateTrueCondition());

            int size = prc.Length;

            for (int i = 0; i < prc.Length; i++)
            {
                string l = prc.GetElement(i).CurrentName;
                int    r = prc.GetElement(i).CurrentProcessId;
            }

            ////This is how you attach to an already opened process
            //foreach (Process procs in Process.GetProcesses())
            //{
            //    if (procs.ProcessName.Equals("Calculator"))
            //    {
            //        int ProcessID = procs.Id;
            //    }
            //}


            IUIAutomationCondition window_cond = new CUIAutomationClass().CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Calculator");

            IUIAutomationElement window = null;
            int attempts = 1;

            while (window == null && attempts < 10)
            {
                window = ROOT.FindFirst(TreeScope.TreeScope_Children, window_cond);
                attempts++;
            }

            IUIAutomationCondition el_cond = new CUIAutomationClass().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "num9Button");

            IUIAutomationElement el = window.FindFirst(TreeScope.TreeScope_Descendants, el_cond);

            var pat = (IUIAutomationInvokePattern)el.GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId);

            pat.Invoke();


            IUIAutomation m = new CUIAutomation();

            IUIAutomationCondition hist_Cond = new CUIAutomationClass().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "HistoryButton");

            IUIAutomationElement hist_El = window.FindFirst(TreeScope.TreeScope_Descendants, hist_Cond);

            var y = hist_El.CurrentHelpText;

            int p = 0;
        }
Ejemplo n.º 21
0
        public string GetMail()
        {
            string strMailContent = "";

            // Try to find a Windows Live Mail window for composing and reading e-mails.
            // Using the Spy tool, the class of the main window can be found. This test
            // app assumes there's only one Windows Live Mail window of interest.
            IntPtr hwnd = Win32.FindWindow("ATH_Note", null);

            if (hwnd != IntPtr.Zero)
            {
                // We found a window, so get the UIA element associated with the window.
                IUIAutomationElement elementMailAppWindow = _automation.ElementFromHandle(
                    hwnd);

                // Find an element somewhere beneath the main window element in the UIA
                // tree which represents the main area where the e-mail content is shown.
                // Using the Inspect SDK tool, we can see that the main e-mail content
                // is contained within an element whose accessible name is "NoteWindow".
                // So create a condition such that the FindFirst() call below will only
                // return an element if its name is "NoteWindow".
                IUIAutomationCondition conditionNote = _automation.CreatePropertyCondition(
                    _propertyIdName, "NoteWindow");

                IUIAutomationElement elementNoteWindow = elementMailAppWindow.FindFirst(
                    TreeScope.TreeScope_Descendants,
                    conditionNote);

                // As it happens, the actual element that supports the Text Pattern is
                // somewhere beneath the "NoteWindow" element in the UIA tree. Using
                // Inspect we can see that there is an element that supports the
                // Text Pattern. Once we have that element, we can avoid a cross-process
                // call to access the Text Pattern object by using cache request.
                IUIAutomationCacheRequest cacheRequest = _automation.CreateCacheRequest();
                cacheRequest.AddPattern(_patternIdTextPattern);

                // Now find the element that supports the Text Pattern. This test app assumes
                // there’s only one element that can be returned which supports the Text Pattern.
                bool fTextPatternSupported = true;
                IUIAutomationCondition conditionTextPattern = _automation.CreatePropertyCondition(
                    _propertyIdIsTextPatternAvailable,
                    fTextPatternSupported);

                IUIAutomationElement elementMailContent = elementMailAppWindow.FindFirstBuildCache(
                    TreeScope.TreeScope_Descendants,
                    conditionTextPattern,
                    cacheRequest);

                // Because the Text Pattern object is cached, we don't have to make a cross-process
                // call here to get object. Later calls which actually use methods and properties
                // on the Text Pattern object will incur cross-proc calls.
                IUIAutomationTextPattern textPattern = (IUIAutomationTextPattern)
                                                       elementMailContent.GetCachedPattern(
                    _patternIdTextPattern);

                // This test app is only interested in getting all the e-mail text, so we get that through
                // the DocumentRange property. A more fully featured app might be interested in getting a
                // collection of Text Ranges from the e-mail. Each range might relate to an individual
                // word or paragraph. Given that a provider which supports the Text Pattern allows a
                // client to find the bounding rectangles of these ranges, the client could choose to use
                // its own method of highlighting the text as the text is being spoken.
                IUIAutomationTextRange rangeDocument = textPattern.DocumentRange;

                // Pass -1 here because we're not interested in limiting the amount of text here.
                strMailContent = rangeDocument.GetText(-1);
            }

            return(strMailContent);
        }
Ejemplo n.º 22
0
        public IUIAutomationElement GetUpdateLinkElement(IUIAutomationElement updateDocumentElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_HyperlinkControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "headerLinkUpdates");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement updateLinkElement = updateDocumentElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return updateLinkElement;
        }
Ejemplo n.º 23
0
        public void GoBack(IUIAutomationElement updateElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Back");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "backButton");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement backElement = updateElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            this.ClickElement(backElement);
            Thread.Sleep(2000);
        }
Ejemplo n.º 24
0
        public IUIAutomationElement GetTopFreeHome(IUIAutomationElement element)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId);

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement topFreeElement = element.FindFirst(TreeScope.TreeScope_Subtree, conditions);
            Console.WriteLine(topFreeElement.CurrentName);

            return topFreeElement;
        }
Ejemplo n.º 25
0
        public IUIAutomationElement GetUpdateDocumentElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "frameHeader");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement updateElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return updateElement;
        }
Ejemplo n.º 26
0
        public IUIAutomationElement GetScrollingContainerElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement frameElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "mainContent");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListControlTypeId);

            conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement contentElement = frameElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Scrolling Container");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId);
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "group");

            conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement scrollingContainerElement = contentElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return scrollingContainerElement;
        }
Ejemplo n.º 27
0
        public IUIAutomationElement GetReportElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Report this review");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId);
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpReportReviewMenu");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return reportElement;
        }
Ejemplo n.º 28
0
        public IUIAutomationElement GetInstallButtonElement(IUIAutomationElement appInfoElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Install");
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpBuyButton");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");
            conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId);

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement installButtonElement = appInfoElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return installButtonElement;
        }
Ejemplo n.º 29
0
        public IUIAutomationElement GetAppInfoElement(IUIAutomationElement rootElement)
        {
            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId);
            conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame");
            conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer");

            IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement appInfoElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions);

            return appInfoElement;
        }
Ejemplo n.º 30
0
        public List <DrawItem> execute()
        {
            List <DrawItem> items = new List <DrawItem>();

            IUIAutomationElement boxToBorder;
            IUIAutomationElement tmpElement;
            Stopwatch            watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            IntPtr storeHwnd = IntPtr.Zero;

            foreach (Process proc in Process.GetProcesses())
            {
                if (proc.MainWindowTitle.StartsWith("Simplify3D"))
                {
                    storeHwnd = proc.MainWindowHandle;
                }
            }

            // IntPtr storeHwnd = NativeMethods.FindWindow ("Qt5QWindowIcon", "Simplify3D (Licensed to ...)");
            IntPtr fffSetings = NativeMethods.FindWindow("Qt5QWindowIcon", "FFF settings");

            bool exit = false;

            if (storeHwnd == IntPtr.Zero)
            {
                exit = true;
            }
            if (storeHwnd != NativeMethods.GetForegroundWindow() && fffSetings != NativeMethods.GetForegroundWindow())
            {
                exit = true;
            }

            if (exit)
            {
                //Highlighter.BufferList(new List<DrawItem>());
                return(items);
            }

            IUIAutomationElement windowApp = _automation.ElementFromHandle(storeHwnd);

            IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[1];
            conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "FFF Settings");
            IUIAutomationCondition conditions    = _automation.CreateAndConditionFromArray(conditionArray);
            IUIAutomationElement   settingsPanel = windowApp.FindFirst(TreeScope.TreeScope_Children, conditionArray[0]);

            //can u see ?
            if (settingsPanel != null)
            {
                try
                {
                    conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Auto-Configure for Material");
                    boxToBorder       = settingsPanel.FindFirst(TreeScope.TreeScope_Descendants, conditionArray[0]);
                    items.Add(new DrawItem(false, boxToBorder.CurrentBoundingRectangle, Color.Orange));
                    conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Auto-Configure for Print Quality");
                    boxToBorder       = settingsPanel.FindFirst(TreeScope.TreeScope_Descendants, conditionArray[0]);
                    items.Add(new DrawItem(false, boxToBorder.CurrentBoundingRectangle, Color.Blue));

                    pane = this.GetSettingsMainPane(settingsPanel);
                    var rowElement = GetRowOfTabs(settingsPanel);

                    var columnElement = GetColumnFromTabRow(rowElement, EXTRUDER);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange));
                    columnElement = GetColumnFromTabRow(rowElement, LAYER);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue));
                    columnElement = GetColumnFromTabRow(rowElement, ADDITIONS);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue));
                    columnElement = GetColumnFromTabRow(rowElement, INFILL);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue));
                    columnElement = GetColumnFromTabRow(rowElement, SUPPORT);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue));
                    columnElement = GetColumnFromTabRow(rowElement, TEMPERATURE);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange));
                    columnElement = GetColumnFromTabRow(rowElement, COOLING);
                    items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange));

                    if (rowElement.CurrentName == EXTRUDER)
                    {
                        tmpElement = this.GetElementFromPane(pane, "Extrusion Multiplier");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange));
                    }
                    else if (rowElement.CurrentName == LAYER)
                    {
                        tmpElement = this.GetElementFromPane(pane, "Primary Layer Height");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                        tmpElement = this.GetElementFromPane(pane, "Top Solid Layers");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                        tmpElement = this.GetElementFromPane(pane, "Bottom Solid Layers");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                    }
                    else if (rowElement.CurrentName == ADDITIONS)
                    {
                        tmpElement = this.GetElementFromPane(pane, "Skirt Layers");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                    }
                    else if (rowElement.CurrentName == INFILL)
                    {
                        tmpElement = this.GetElementFromPane(pane, "Interior Fill Percentage");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                    }
                    else if (rowElement.CurrentName == SUPPORT)
                    {
                        tmpElement = this.GetElementFromPane(pane, "Support Infill Percentage");
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue));
                    }
                    else if (rowElement.CurrentName == TEMPERATURE)
                    {
                        tmpElement = this.GetBoxFromPane(pane, UIA_ControlTypeIds.UIA_ListControlTypeId);
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange));
                    }
                    else if (rowElement.CurrentName == COOLING)
                    {
                        tmpElement = this.GetBoxFromPane(pane, UIA_ControlTypeIds.UIA_TreeControlTypeId);
                        items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange));
                    }
                }
                catch (NullReferenceException)
                {
                    Console.WriteLine("shit happens");
                }

                watch.Stop();
                int timeout = (1000 / 75) - (int)watch.ElapsedMilliseconds;

                //Thread.Sleep(timeout);
            }
            //Highlighter.BufferList(items);
            return(items);
            // grab the context from the state
        }