/// <summary>
        ///  /// </summary>
        /// <param name="element"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        internal static IUiElement[] GetParentOrAncestor(this IUiElement element, classic.TreeScope scope)
        {
            var walker =
                new classic.TreeWalker(
                    classic.Condition.TrueCondition);

            var ancestors =
                new List <IUiElement>();

            try {
                IUiElement testParent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));

                if (scope == classic.TreeScope.Parent || scope == classic.TreeScope.Ancestors)
                {
                    if (testParent.GetCurrent() != UiElement.RootElement.GetCurrent())
                    {
                        ancestors.Add(testParent);
                    }

                    if ((testParent.Equals(UiElement.RootElement) && testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) ||
                        scope == classic.TreeScope.Parent)
                    {
                        return(ancestors.ToArray());
                    }
                }

                while (testParent != null &&
                       (int)testParent.GetCurrent().ProcessId > 0 &&
                       !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent()))
                {
                    testParent =
                        AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement));

                    if (testParent != null &&
                        (int)testParent.GetCurrent().ProcessId > 0 &&
                        !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent()))
                    {
                        ancestors.Add(testParent);
                    }
                    else
                    {
                        break;
                    }
                }
                return(ancestors.ToArray());
            } catch {
                return(ancestors.ToArray());
            }
        }
Пример #2
0
        /// <summary>
        ///  /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        internal static IUiElement GetAncestorWithHandle(this IUiElement element)
        {
            var walker =
                new classic.TreeWalker(
                    classic.Condition.TrueCondition);
            
            /*
            TreeWalker walker =
                new TreeWalker(
                    System.Windows.Automation.Condition.TrueCondition);
            */
            
            try {
                
                // 20140102
                // IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement()));
                IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));
                while (testparent != null &&
                    // 20143012
                       // testparent.Current.NativeWindowHandle == 0) {
                        testparent.GetCurrent().NativeWindowHandle == 0) {
                    testparent =
                        // 20140102
                        // AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement()));
                        AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement() as classic.AutomationElement));
                    if (testparent != null &&
                        // 20143012
//                        (int)testparent.Current.ProcessId > 0 &&
//                        testparent.Current.NativeWindowHandle != 0) {
                        (int)testparent.GetCurrent().ProcessId > 0 &&
                        testparent.GetCurrent().NativeWindowHandle != 0) {
                        
                        return testparent;
                    }
                }
                // 20143012
                // return testparent.Current.NativeWindowHandle != 0 ? testparent : null;
                return testparent.GetCurrent().NativeWindowHandle != 0 ? testparent : null;
                
            } catch {
                return null;
            }
        }
        /// <summary>
        ///  /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        internal static IUiElement GetAncestorWithHandle(this IUiElement element)
        {
            var walker =
                new classic.TreeWalker(
                    classic.Condition.TrueCondition);

            /*
             * TreeWalker walker =
             *  new TreeWalker(
             *      System.Windows.Automation.Condition.TrueCondition);
             */

            try {
                // 20140102
                // IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement()));
                IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));
                while (testparent != null &&
                       // 20143012
                       // testparent.Current.NativeWindowHandle == 0) {
                       testparent.GetCurrent().NativeWindowHandle == 0)
                {
                    testparent =
                        // 20140102
                        // AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement()));
                        AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement() as classic.AutomationElement));
                    if (testparent != null &&
                        // 20143012
//                        (int)testparent.Current.ProcessId > 0 &&
//                        testparent.Current.NativeWindowHandle != 0) {
                        (int)testparent.GetCurrent().ProcessId > 0 &&
                        testparent.GetCurrent().NativeWindowHandle != 0)
                    {
                        return(testparent);
                    }
                }
                // 20143012
                // return testparent.Current.NativeWindowHandle != 0 ? testparent : null;
                return(testparent.GetCurrent().NativeWindowHandle != 0 ? testparent : null);
            } catch {
                return(null);
            }
        }
Пример #4
0
        public static IUiElement PerformNavigateToParent(this IUiElement element)
        {
            IUiElement result = null;

            var walker = new classic.TreeWalker(classic.Condition.TrueCondition);

            try {
                result = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));
            } catch {
            }

            return(result);
        }
        public static IUiElement PerformNavigateToParent(this IUiElement element)
        {
            IUiElement result = null;

            var walker = new classic.TreeWalker(classic.Condition.TrueCondition);

            try {
                result = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));
            } catch {
            }

            return result;
        }
Пример #6
0
 /// <summary>
 ///  /// </summary>
 /// <param name="element"></param>
 /// <param name="scope"></param>
 /// <returns></returns>
 internal static IUiElement[] GetParentOrAncestor(this IUiElement element, classic.TreeScope scope)
 {
     var walker =
         new classic.TreeWalker(
             classic.Condition.TrueCondition);
     
     var ancestors =
         new List<IUiElement>();
     
     try {
         
         IUiElement testParent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement));
             
         if (scope == classic.TreeScope.Parent || scope == classic.TreeScope.Ancestors) {
             
             if (testParent.GetCurrent() != UiElement.RootElement.GetCurrent()) {
                 ancestors.Add(testParent);
             }
             
             if ((testParent.Equals(UiElement.RootElement) && testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) ||
                 scope == classic.TreeScope.Parent) {
                 return ancestors.ToArray();
             }
         }
         
         while (testParent != null &&
             (int)testParent.GetCurrent().ProcessId > 0 &&
             !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) {
             
             testParent =
                 AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement));
             
             if (testParent != null &&
                 (int)testParent.GetCurrent().ProcessId > 0 &&
                 !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) {
                 
                 ancestors.Add(testParent);
             } else {
                 break;
             }
         }
         return ancestors.ToArray();
     } catch {
         return ancestors.ToArray();
     }
 }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <param name="element"></param>
        internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured)
        {
            var walker =
                new classic.TreeWalker(
                    classic.Condition.TrueCondition);
            
            /*
            TreeWalker walker =
                new TreeWalker(
                    System.Windows.Automation.Condition.TrueCondition);
            */
            
            try
            {
                // commented out 201206210
                //testparent =
                //    walker.GetParent(element);
                IUiElement testParent = element;
                
                // 20140312
                // while (testParent != null && (int)testParent.Current.ProcessId > 0) {
                while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0) {
                    
                    testParent =
                        // 20140102
                        // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement()));
                        AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement));
                    
                    // 20140312
                    // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue;
                    if (testParent == null || (int) testParent.GetCurrent().ProcessId <= 0) continue;
                    if (testParent == cmdlet.OddRootElement)
                    { testParent = null; }
                    else{
                        string parentControlType =
                            // getControlTypeNameOfAutomationElement(testparent, element);
                            // testparent.Current.ControlType.ProgrammaticName.Substring(
                            // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1);
                            //  // experimental
                            // 20140312
//                            testParent.Current.ControlType.ProgrammaticName.Substring(
//                                testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1);
                            testParent.GetCurrent().ControlType.ProgrammaticName.Substring(
                                testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1);
                        //  // if (parentControlType.Length == 0) {
                        // break;
                        //}
                            
                        // in case this element is an upper-level Pane
                        // residing directrly under the RootElement
                        // change type to window
                        // i.e. Get-UiaPane - >  Get-UiaWindow
                        // since Get-UiaPane is unable to get something more than
                        // a window's child pane control
                        if (parentControlType == "Pane" || parentControlType == "Menu") {
                            
                            // 20131109
                            //if (walker.GetParent(testParent) == cmdlet.rootElement) {
                            // 20131112
                            //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) {
                            // 20131118
                            // property to method
                            //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) {
                            // 20140102
                            // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) {
                            if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement) {
                                parentControlType = "Window";
                            }
                        }
                            
                        string parentVerbosity =
                            @"Get-Uia" + parentControlType;
                        try {
                            // 20140312
//                            if (testParent.Current.AutomationId.Length > 0) {
//                                parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'");
                            if (testParent.GetCurrent().AutomationId.Length > 0) {
                                parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'");
                            }
                        }
                        catch {
                        }
                        if (!cmdlet.NoClassInformation) {
                            try {
                                // 20140312
//                                if (testParent.Current.ClassName.Length > 0) {
//                                    parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'");
                                if (testParent.GetCurrent().ClassName.Length > 0) {
                                    parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'");
                                }
                            }
                            catch {
                            }
                        }
                        try {
                            // 20140312
//                            if (testParent.Current.Name.Length > 0) {
//                                parentVerbosity += (" -Name '" + testParent.Current.Name + "'");
                            if (testParent.GetCurrent().Name.Length > 0) {
                                parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'");
                            }
                        }
                        catch {
                        }

                        if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity)
                            continue;
                        cmdlet.LastRecordedItem.Add(parentVerbosity);
                        cmdlet.WriteVerbose(parentVerbosity);
                    }
                }
            }
            catch (Exception eErrorInTheInnerCycle) {
                cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message);
                // _errorMessageInTheInnerCycle =
                errorMessage =
                    eErrorInTheInnerCycle.Message;
                // _errorInTheInnerCycle = true;
                errorOccured = true;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <param name="element"></param>
        internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured)
        {
            var walker =
                new classic.TreeWalker(
                    classic.Condition.TrueCondition);

            /*
             * TreeWalker walker =
             *  new TreeWalker(
             *      System.Windows.Automation.Condition.TrueCondition);
             */

            try
            {
                // commented out 201206210
                //testparent =
                //    walker.GetParent(element);
                IUiElement testParent = element;

                // 20140312
                // while (testParent != null && (int)testParent.Current.ProcessId > 0) {
                while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0)
                {
                    testParent =
                        // 20140102
                        // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement()));
                        AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement));

                    // 20140312
                    // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue;
                    if (testParent == null || (int)testParent.GetCurrent().ProcessId <= 0)
                    {
                        continue;
                    }
                    if (testParent == cmdlet.OddRootElement)
                    {
                        testParent = null;
                    }
                    else
                    {
                        string parentControlType =
                            // getControlTypeNameOfAutomationElement(testparent, element);
                            // testparent.Current.ControlType.ProgrammaticName.Substring(
                            // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1);
                            //  // experimental
                            // 20140312
//                            testParent.Current.ControlType.ProgrammaticName.Substring(
//                                testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1);
                            testParent.GetCurrent().ControlType.ProgrammaticName.Substring(
                                testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1);
                        //  // if (parentControlType.Length == 0) {
                        // break;
                        //}

                        // in case this element is an upper-level Pane
                        // residing directrly under the RootElement
                        // change type to window
                        // i.e. Get-UiaPane - >  Get-UiaWindow
                        // since Get-UiaPane is unable to get something more than
                        // a window's child pane control
                        if (parentControlType == "Pane" || parentControlType == "Menu")
                        {
                            // 20131109
                            //if (walker.GetParent(testParent) == cmdlet.rootElement) {
                            // 20131112
                            //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) {
                            // 20131118
                            // property to method
                            //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) {
                            // 20140102
                            // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) {
                            if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement)
                            {
                                parentControlType = "Window";
                            }
                        }

                        string parentVerbosity =
                            @"Get-Uia" + parentControlType;
                        try {
                            // 20140312
//                            if (testParent.Current.AutomationId.Length > 0) {
//                                parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'");
                            if (testParent.GetCurrent().AutomationId.Length > 0)
                            {
                                parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'");
                            }
                        }
                        catch {
                        }
                        if (!cmdlet.NoClassInformation)
                        {
                            try {
                                // 20140312
//                                if (testParent.Current.ClassName.Length > 0) {
//                                    parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'");
                                if (testParent.GetCurrent().ClassName.Length > 0)
                                {
                                    parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'");
                                }
                            }
                            catch {
                            }
                        }
                        try {
                            // 20140312
//                            if (testParent.Current.Name.Length > 0) {
//                                parentVerbosity += (" -Name '" + testParent.Current.Name + "'");
                            if (testParent.GetCurrent().Name.Length > 0)
                            {
                                parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'");
                            }
                        }
                        catch {
                        }

                        if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity)
                        {
                            continue;
                        }
                        cmdlet.LastRecordedItem.Add(parentVerbosity);
                        cmdlet.WriteVerbose(parentVerbosity);
                    }
                }
            }
            catch (Exception eErrorInTheInnerCycle) {
                cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message);
                // _errorMessageInTheInnerCycle =
                errorMessage =
                    eErrorInTheInnerCycle.Message;
                // _errorInTheInnerCycle = true;
                errorOccured = true;
            }
        }