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


C# AutomationElement.FindFirst方法代码示例

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


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

示例1: ButtonClick

        private static bool ButtonClick(AutomationElement inElement, string automationId)
        {
            PropertyCondition btnCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);

            Console.WriteLine("Searching for the {0} button...", automationId);
            AutomationElement control = inElement.FindFirst(TreeScope.Descendants, btnCondition);
            if (control != null)
            {
                Console.WriteLine("Clicking the {0} button", automationId);

                object controlType = control.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty);
                if (controlType == ControlType.Button)
                {
                    InvokePattern clickCommand = control.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                    clickCommand.Invoke();
                }
                else if (controlType == ControlType.RadioButton)
                {
                    SelectionItemPattern radioCheck = control.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                    radioCheck.Select();
                }
                System.Threading.Thread.Sleep(2000);
                Console.WriteLine("Button {0} clicked.", automationId);

                return true;
            }
            else
            {
                Console.WriteLine("Could not find button {0} ", automationId);
                return false;
            }
        }
开发者ID:svetlik,项目名称:AutoInstall,代码行数:32,代码来源:AutoInstall.cs

示例2: InvokeDialogOk

        private void InvokeDialogOk(Process process, AutomationElement window, string dialogClass, string okName)
        {
            process.WaitForInputIdle();
            AutomationElement dialog = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, dialogClass));
            while(dialog == null)
            {
                Thread.Sleep(16);
                dialog = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, dialogClass));
            }
            AutomationElement button = dialog.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, okName));

            object invoke;
            if (button.TryGetCurrentPattern(InvokePattern.Pattern, out invoke))
            {
                ((InvokePattern)invoke).Invoke();
            }
        }
开发者ID:alanjg,项目名称:Heroes,代码行数:17,代码来源:ArchangelDriver.cs

示例3: getAutomationElement

        public static AutomationElement getAutomationElement(AutomationElement parent, TreeScope scope, ControlType type, string name)
        {
            var element = parent.FindFirst(scope, new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, type),
                new PropertyCondition(AutomationElement.NameProperty, name),
                Automation.ControlViewCondition));

            return element;
        }
开发者ID:xia-sava,项目名称:PVCtrl,代码行数:9,代码来源:PvCtrlUtil.cs

示例4: FindWindowByName

        public static AutomationElement FindWindowByName(AutomationElement rootElement, string name, ControlType type)
        {
            PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, name);

            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            AndCondition andCondition = new AndCondition(nameCondition, typeCondition);

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

示例5: FindElementById

        public static AutomationElement FindElementById(AutomationElement parentElement, string automationID, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

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

示例6: GetElement

        public AutomationElement GetElement(AutomationElement rootElement, AutomationProperty property, object value, TreeScope searchScope)
        {
            AutomationElement aeMainWindow = null;

            int numWaits = 0;
            do
            {
                aeMainWindow = rootElement.FindFirst(searchScope, new PropertyCondition(property, value));
                ++numWaits;
                Thread.Sleep(200);
            } while (aeMainWindow == null && numWaits < 50);
            return aeMainWindow;
        }
开发者ID:prasannarhegde2015,项目名称:MySQLBackupCsharpScript,代码行数:13,代码来源:SampleUIAAutoamtion.cs

示例7: ExtractElement

        /// <summary>
        /// Extract Window from parent window
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="titleName"></param>
        /// <returns></returns>
        public static AutomationElement ExtractElement(AutomationElement parent, string nameValue, TreeScope treeScope)
        {
            ValidateArgumentNotNull(parent, "Extract Window from parent window");
            Condition condition = new PropertyCondition(AutomationElement.NameProperty, nameValue);
            AutomationElement appElement;
            DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
            do
            {
                appElement = parent.FindFirst(treeScope, condition);
            } while (appElement == null && DateTime.Now < timeOut);

            return appElement;
        }
开发者ID:barbarossia,项目名称:DIS,代码行数:19,代码来源:Helper.cs

示例8: Window

		public Window(IntPtr hWnd)
			: base(hWnd)
		{
			Angle = 0;
			Scale = 1;
			hasMenu = false;

			Contacts = new WindowContacts(this);

			automationElement = AutomationElement.FromHandle(hWnd);
			PropertyCondition condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuBar);
			AutomationElement first = automationElement.FindFirst(TreeScope.Descendants, condition);
			if (first != null && !first.Current.Name.Equals("System Menu Bar"))
				hasMenu = true;
		}
开发者ID:zhuangfangwang,项目名称:ise,代码行数:15,代码来源:Window.cs

示例9: GetElement

 /// <summary>
 /// This method returns an element searched by its control type from the tree.
 /// </summary>
 /// <param name="root">Root Element of the control</param>
 /// <param name="controlType">Control Type of the element</param>
 /// <returns>Automation Element of teh control</returns>
 public static AutomationElement GetElement(AutomationElement root, ControlType controlType)
 {
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (controlType == null)
     {
         throw new ArgumentNullException("controlType");
     }
     else
     {
         PropertyCondition condType = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
         return root.FindFirst(TreeScope.Descendants, condType);
     }
 }
开发者ID:hxhlb,项目名称:wwt-tile-sdk,代码行数:22,代码来源:CommonHelperMethods.cs

示例10: AutomationElementFromCustomId

        public const int TIMEWAIT = 100;                        // Used for starting process

        #endregion

        #region AutomationElementFromCustomId
        // -------------------------------------------------------------------
        // Finds an automation element from a given Automation ID
        // -------------------------------------------------------------------
        static public AutomationElement AutomationElementFromCustomId(AutomationElement element, object identifier, bool verbose)
        {
            Library.ValidateArgumentNonNull(element, "Automation Element");
            Library.ValidateArgumentNonNull(identifier, "Automation ID");

            if (verbose == true)
                /* changing to new flexible logging */
                //Logger.LogComment("Looking for control (" + identifier + ")");
                UIVerifyLogger.LogComment("Looking for control (" + identifier + ")");

            AutomationElement ae;
            ae = element.FindFirst(TreeScope.Children | TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, identifier));
            if (ae == null)
            {
                throw new ArgumentException("Could not identify the element based on the AutomationIdProperty");
            }

            return ae;
        }
开发者ID:jeffras,项目名称:uiverify,代码行数:27,代码来源:TextLibrary.cs

示例11: WaitForElementByName

        public static AutomationElement WaitForElementByName(AutomationElement element, int seconds, AutomationElement parent, string name)
        {
            while (element == null)
            {
                Thread.Sleep(1000);

                seconds--;

                element = parent.FindFirst(TreeScope.Descendants,
                 new PropertyCondition(AutomationElement.NameProperty, name));

                if (seconds == 0)
                {
                    throw new NoSuchElementException("Can't find element or it's not loaded!");
                }
            }

            return element;
        }
开发者ID:ekostadinov,项目名称:MyProjects,代码行数:19,代码来源:SilverlightPage.cs

示例12: FindBy

        static AutomationElement FindBy(AutomationElement root, int wait, PropertyCondition condition)
        {
            var waitCount = 0;
            AutomationElement node;

            do
            {
                node = root.FindFirst(
                    TreeScope.Descendants,
                    condition);
           
                if(node == null && waitCount <= wait)
                    Thread.Sleep(ImplicitWaitInterval);

                waitCount++;
            } while (node == null && waitCount <= wait);

            return node;
        }
开发者ID:piriej,项目名称:Assignment3,代码行数:19,代码来源:AutomationElementHelpers.cs

示例13: FindFirst

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

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (DateTime.Now <= dtn)
            {
                var element = parent.FindFirst(scope, condition);
                if (element != null)
                {
                    return element;
                }
            }

            return null;
        }
开发者ID:horst14,项目名称:Winium.Cruciatus,代码行数:20,代码来源:AutomationElementHelper.cs

示例14: InvokeMenuItem

 private void InvokeMenuItem(Process process, AutomationElement window, string menu, string menuItem)
 {
     AutomationElement menuElement = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu));
     object menuExpand;
     if (menuElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out menuExpand))
     {
         ((ExpandCollapsePattern)menuExpand).Expand();
         process.WaitForInputIdle();
         AutomationElement menuItemElement = menuElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menuItem));
         while (menuItemElement == null)
         {
             Thread.Sleep(16);
             menuItemElement = menuElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menuItem));
         }
         object menuItemInvoke;
         if (menuItemElement.TryGetCurrentPattern(InvokePattern.Pattern, out menuItemInvoke))
         {
             ((InvokePattern)menuItemInvoke).Invoke();
         }
     }
 }
开发者ID:alanjg,项目名称:Heroes,代码行数:21,代码来源:ArchangelDriver.cs

示例15: OvertimeWindowApproachingCancel

        public static bool OvertimeWindowApproachingCancel(AutomationElement parent)
        {
            if (parent == null)
                return false;

            var cancel = parent.FindFirst(TreeScope.Descendants,
                new System.Windows.Automation.PropertyCondition(
                    AutomationElement.AutomationIdProperty, "_CancelButton"));

            object pattern;

            if (cancel.TryGetCurrentPattern(InvokePattern.Pattern, out pattern))
            {
                var buttonPattern = pattern as InvokePattern;
                if (buttonPattern != null)
                {
                    buttonPattern.Invoke();
                    return true;
                }
            }

            return false;
        }
开发者ID:kkodandarama,项目名称:EllisWinAppTest,代码行数:23,代码来源:DispatchProfileWindow.cs


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