当前位置: 首页>>代码示例>>C#>>正文


C# AutomationElement.FindAll方法代码示例

本文整理汇总了C#中System.Windows.Automation.AutomationElement.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.FindAll方法的具体用法?C# AutomationElement.FindAll怎么用?C# AutomationElement.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Automation.AutomationElement的用法示例。


在下文中一共展示了AutomationElement.FindAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTestInternal

        private static void RunTestInternal(IEnumerable<AutomationTest> automationTests, AutomationElement element, IWin32Window parentWindow, AutomationTestManager manager)
        {
            //create window
            RunningTestsWindow testWindow = new RunningTestsWindow();

            if (manager._testChildren)
            {
                //// Determine if this is a control/pattern/Automation test
                //// Construct the PropertyCondition
                Condition condition = null;

                //// Add all the tests
                foreach (AutomationTest test in automationTests)
                {

                    // The tests are within a class the defines what pattern type this in is
                    StringBuilder buffer = new StringBuilder(((MainWindow)parentWindow)._automationTests._testsTreeView.SelectedNode.FullPath);
                    switch (test.Type)
                    {
                        case TestTypes.AutomationElementTest:
                            // Tests\Automation Element Tests\Priority 2 Tests\AutomationElement.PropertyChange.Enabled.1
                            condition = Condition.TrueCondition;
                            break;
                        case TestTypes.ControlTest:
                            {
                                // Tests\Control Tests\Slider\Priority 1 Tests\BulkAdd.1
                                buffer.Replace(@"Tests\Control Tests\", "");
                                int indexOf = buffer.ToString().IndexOf(@"\");
                                buffer.Remove(indexOf, buffer.Length - indexOf);
                                condition = new PropertyCondition(AutomationElement.ControlTypeProperty, GetControlType(buffer.ToString()));
                            }
                            break;
                        case TestTypes.PatternTest:
                            {
                                // Tests\Pattern Tests\Grid\Priority 1 Tests\GridPattern.S.1.1/2/3
                                buffer.Replace(@"Tests\Pattern Tests\", "");
                                int indexOf = buffer.ToString().IndexOf(@"\");
                                buffer.Remove(indexOf, buffer.Length - indexOf);
                                condition = new PropertyCondition(GetProperty("Is" + buffer.ToString() + "PatternAvailableProperty"), true);
                            }
                            break;
                        default:
                            throw new ArgumentException("Cannot run " + test.Type + " tests");

                    }
                    //// Find all elements
                    AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, condition);
                    foreach (AutomationElement temp in collection)
                        testWindow.AddTest(test, temp);
                }

            }
            else
            {
                //add all tests
                foreach (AutomationTest test in automationTests)
                    testWindow.AddTest(test, element);
            }
            //let them run
            testWindow.ShowAndRunTests(manager, parentWindow);
        }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:61,代码来源:AutomationTestManager.cs

示例2: TextPatternRangeFromChildGood

 public static void TextPatternRangeFromChildGood(AutomationElement element)
 {
     object patternObj = null;
     if (GetPatternObject(element, TextPattern.Pattern, ref patternObj))
     {
         TextPattern pattern = (TextPattern)patternObj;
         Dump("TextPattern.GetVisibleRanges", true, element);
         try
         {
             AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, Condition.TrueCondition);
             object property = pattern.RangeFromChild(collection[_rnd.Next(collection.Count)]);
         }
         catch (Exception exception)
         {
             VerifyException(element, exception,
                 typeof(ElementNotAvailableException),
                 typeof(InvalidOperationException));
         }
     }
 }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:20,代码来源:stress.cs

示例3: FindElementsByName

 // 指定したName属性に一致するAutomationElementをすべて返します
 private static IEnumerable<AutomationElement> FindElementsByName(AutomationElement rootElement, string name)
 {
     return rootElement.FindAll(
         TreeScope.Element | TreeScope.Descendants,
         new PropertyCondition(AutomationElement.NameProperty, name))
         .Cast<AutomationElement>();
 }
开发者ID:shigusa,项目名称:Senri,代码行数:8,代码来源:WindowsUIAutomationCommand.cs

示例4: GetAllChildNodes

 public AutomationElementCollection GetAllChildNodes(AutomationElement element, AutomationProperty automationProperty, object value, TreeScope treeScope)
 {
     var allChildNodes = element.FindAll(treeScope, GetPropertyCondition(automationProperty, value));
     if (allChildNodes == null)
         throw new ElementNotAvailableException("Not able to find the child nodes of the element");
     return allChildNodes;
 }
开发者ID:prasannarhegde2015,项目名称:MySQLBackupCsharpScript,代码行数:7,代码来源:SampleUIAAutoamtion.cs

示例5: FindElementByClassName

        public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
开发者ID:tankxiao,项目名称:tankproject,代码行数:10,代码来源:AutomationBuild.cs

示例6: StartApp

 /// <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));
 }
开发者ID:CasperWu,项目名称:UITestCalc,代码行数:22,代码来源:Calc.cs

示例7: FindAll

        internal static IEnumerable<AutomationElement> FindAll(
            AutomationElement parent, 
            TreeScope scope, 
            Condition condition, 
            int timeout)
        {
            var dtn = DateTime.Now.AddMilliseconds(timeout);

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (DateTime.Now <= dtn)
            {
                var elements = parent.FindAll(scope, condition);
                if (elements.Count > 0)
                {
                    return elements.Cast<AutomationElement>();
                }
            }

            return Enumerable.Empty<AutomationElement>();
        }
开发者ID:horst14,项目名称:Winium.Cruciatus,代码行数:20,代码来源:AutomationElementHelper.cs

示例8: GetCurrentUrl

        private string GetCurrentUrl(AutomationElement chrome)
        {
            try
            {
                string url = null;

                var edits = chrome.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                if (edits.Count == 0) return null;

                foreach (AutomationElement edit in edits)
                {
                    url = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;

                    if (!string.IsNullOrWhiteSpace(url))
                        return base.GetUrl(url);
                }
            }
            catch
            { }

            return null;
        }
开发者ID:Usagination,项目名称:Decchi,代码行数:22,代码来源:Chrome.cs

示例9: GetChildren

        public static AutomationElement GetChildren(AutomationElement parent, string NameStartsWith = "", string ControlTypeStartsWith = "")
        {
            if (parent == null) {
                throw new ArgumentException();
            }
            AutomationElementCollection collection = parent.FindAll(TreeScope.Children, Condition.TrueCondition);
            if (collection != null) {
                //Cast AutomationElementCollection into
                //AutomationElement List
                List<AutomationElement> aeList = new List<AutomationElement>(collection.Cast<AutomationElement>());
                AutomationElement aeSelected = null;

                if (NameStartsWith == "" && ControlTypeStartsWith == "") return null;

                if (NameStartsWith != "" && ControlTypeStartsWith == "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
                }
                if (NameStartsWith == "" && ControlTypeStartsWith != "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
                }
                if (NameStartsWith != "" && ControlTypeStartsWith != "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
                    if (aeSelected == null) aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
                }

                if (aeSelected != null)
                    return aeSelected;
                else {
                    return null;
                }

            } else {
                // some error occured
                return null;
            }
        }
开发者ID:JGEsteves89,项目名称:DaCMain,代码行数:36,代码来源:HHMonitor.cs

示例10: UIA_ClickButtonByName

        //**************************************************************************************************************************************************************


        public static void UIA_ClickButtonByName(AutomationElement uiaWindow, Window window, string name)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
                AutomationElementCollection buttons = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement e in buttons)
                {
                    if (e.Current.Name.Equals(name))
                    {
                        TestStack.White.UIItems.Button t = new TestStack.White.UIItems.Button(e, window.ActionListener);
                        t.Click();
                    }
                }
                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
开发者ID:vincentraj,项目名称:QBSilk4NetWhiteFramework,代码行数:34,代码来源:Actions.cs

示例11: SearchByTextViaUIA

 internal void SearchByTextViaUIA(
     GetControlCmdletBase cmdlet,
     AutomationElement inputObject,
     System.Windows.Automation.AndCondition conditionsForTextSearch)
 {
     this.WriteVerbose(cmdlet, "Text search");
     AutomationElementCollection textSearchCollection = inputObject.FindAll(TreeScope.Descendants, conditionsForTextSearch);
     if (null != textSearchCollection && 0 < textSearchCollection.Count) {
         this.WriteVerbose(cmdlet, "There are " + textSearchCollection.Count.ToString() + " elements");
         foreach (AutomationElement element in textSearchCollection) {
             aeCtrl.Add(element);
         }
     }
 }
开发者ID:uiatester,项目名称:STUPS,代码行数:14,代码来源:CommonCmdletBase.cs

示例12: SearchByExactConditionsViaUIA

        internal void SearchByExactConditionsViaUIA(
            GetControlCmdletBase cmdlet,
            AutomationElement inputObject,
            System.Windows.Automation.AndCondition conditions)
        {
            #region the -First story
            // 20120824
            //aeCtrl =
            // 20120921
            #region -First
            //                                    if (cmdlet.First) {
            //                                        AutomationElement tempFirstElement =
            //                                            inputObject.FindFirst(
            //                                                System.Windows.Automation.TreeScope.Descendants,
            //                                                conditions);
            //                                        if (null != tempFirstElement) {
            //                                            if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
            //                                                aeCtrl.Add(tempFirstElement);
            //                                            } else {
            //                                                if (testControlWithAllSearchCriteria(
            //                                                    cmdlet,
            //                                                    cmdlet.SearchCriteria,
            //                                                    tempFirstElement)) {
            //                                                    aeCtrl.Add(tempFirstElement);
            //                                                }
            //                                            }
            //                                        }
            //                                    } else {
            #endregion -First
            // 20120823
            //cmdlet.InputObject.FindFirst(System.Windows.Automation.TreeScope.Descendants,

            // 20120824
            // 20120917
            #region -First
            //                                    }
            #endregion -First
            //else if (UIAutomation.CurrentData.LastResult
            #endregion the -First story

            //internal void SearchByExactConditionsViaUIA(System.Windows.Automation.AndCondition conditions, ref bool notTextSearch, ref System.Windows.Automation.AndCondition conditionsForWildCards, ref AutomationElement inputObject, ref int processId, GetControlCmdletBase cmdlet)
            //{

            if (conditions != null) {
                if (inputObject != null && (int)inputObject.Current.ProcessId > 0) {
                    AutomationElementCollection tempCollection = inputObject.FindAll(System.Windows.Automation.TreeScope.Descendants, conditions);
                    foreach (AutomationElement tempElement in tempCollection) {
                        if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
                            aeCtrl.Add(tempElement);
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                        } else {
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: checking search criteria");
                            if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement)) {
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: the control matches the search criteria");
                                aeCtrl.Add(tempElement);
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                            }
                        }
                    }
                }
            }
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:62,代码来源:CommonCmdletBase.cs

示例13: HelperGetContainersSelectableItems

        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal ArrayList HelperGetContainersSelectableItems(AutomationElement selectionContainer)
        {
            ArrayList list = new ArrayList();

            // Win32 radio buttons do not have containers, so bail.
            if (selectionContainer != null)
            {

                PropertyCondition pc = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);

                foreach (AutomationElement element in selectionContainer.FindAll(TreeScope.Subtree, pc))
                {
                    // Don't want to include any "Previous" in calendar controls
                    if (element.Current.AutomationId.IndexOf("Previous") == -1 && element.Current.AutomationId.IndexOf("Next") == -1)
                    {
                        list.Add(element);
                    }
                }
            }
            return list;
        }
开发者ID:TestStack,项目名称:UIAVerify,代码行数:24,代码来源:TestObject.cs

示例14: UIA_SetFocusOfFirstTextBox

        //**************************************************************************************************************************************************************
        public static void UIA_SetFocusOfFirstTextBox(AutomationElement uiaWindow, Window window)
        {
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text);
                AutomationElementCollection textBoxes = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement textBox in textBoxes)
                {
                    TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(textBox, window.ActionListener);
                    t.Focus();
                    t.Click();
                    Thread.Sleep(int.Parse(Execution_Speed));
                    break;
                }

            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
开发者ID:nhaloi,项目名称:QBWhiteFramework,代码行数:24,代码来源:Actions.cs

示例15: UIA_GetChildWindow

        //**************************************************************************************************************************************************************
        public static AutomationElement UIA_GetChildWindow(AutomationElement appWindow, string childWindowName)
        {
            AutomationElement childWindow = null;

            try
            {
                PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
                PropertyCondition windowNameCondition = new PropertyCondition(AutomationElement.NameProperty, childWindowName);
                AndCondition windowCondition = new AndCondition(windowTypeCondition, windowNameCondition);
                AutomationElement window = appWindow.FindFirst(TreeScope.Children, windowCondition);

                AutomationElementCollection windows = appWindow.FindAll(TreeScope.Descendants, windowTypeCondition);

                foreach (AutomationElement w in windows)
                {
                    if (w.Current.Name.Equals(childWindowName) || w.Current.Name.Contains(childWindowName))
                    {
                        childWindow = w;
                        break;
                    }
                }

                return childWindow;
            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
开发者ID:nhaloi,项目名称:QBWhiteFramework,代码行数:32,代码来源:Actions.cs


注:本文中的System.Windows.Automation.AutomationElement.FindAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。