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


C# AutomationElement.SetFocus方法代码示例

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


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

示例1: MouseClick

        public static void MouseClick(AutomationElement element)
        {
            element.ScrollToIfPossible();
            element.SetFocus();

            var clickablePoint = element.GetClickablePoint();
            Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
            mouse_event(MOUSEEVENTLF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTLF_LEFTUP, 0, 0, 0, 0);
        }
开发者ID:hbqy90,项目名称:RAutomation,代码行数:10,代码来源:Clicker.cs

示例2: AutomationElementSetFocus

 public static void AutomationElementSetFocus(AutomationElement element)
 {
     Dump("SetFocus()", true, element);
     try
     {
         element.SetFocus();
     }
     catch (Exception exception)
     {
         VerifyException(element, exception,
             typeof(ElementNotAvailableException),
             typeof(ElementNotEnabledException),
             typeof(InvalidOperationException) /* {"The target element could not receive focus."}*/
             );
             
     }
 }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:17,代码来源:stress.cs

示例3: HelperPressButton

        /// -------------------------------------------------------------------
        /// <summary>Helper: Press button</summary>
        /// -------------------------------------------------------------------
        void HelperPressButton(AutomationElement element, ActionMethod actionBY, CheckType checkType)
        {
            Library.ValidateArgumentNonNull(element, "Button AutomationElement");

            string name = element.Current.Name;

            switch (actionBY)
            {
                case ActionMethod.KeyPadOnly:
                    {
                        string buffer = element.Current.AccessKey;
                        if (!string.IsNullOrEmpty(buffer))
                        {
                            // There is an access key so use it
                            Comment("Pressing keyboard access key \"" + element.Current.AccessKey + "\"");
                            Input.SendKeyboardInput(element.Current.AccessKey);
                        }
                        else
                        {
                            // No access key so set focus and press enter
                            Comment("Setting focus to \"{0}\" and pressing ENTER", element.Current.Name);
                            element.SetFocus();
                            Input.SendKeyboardInput(System.Windows.Input.Key.Enter);
                        }
                    }
                    break;
                case ActionMethod.MouseClick:
                    {
                        Comment("Moving mouse to \"" + element.Current.Name + "\" and left clicking");
                        Input.MoveToAndClick(element);
                    }
                    break;
                default:
                    {
                        if (!(bool)element.GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty))
                            ThrowMe(checkType, "Button \"" + name + "\" does not support Invoke pattern");

                        Comment("Calling InvokePattern.Invoke() on \"" + name + "\"");
                        ((InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
                    }
                    break;
            }
        }
开发者ID:TestStack,项目名称:UIAVerify,代码行数:46,代码来源:ScreenReader.cs

示例4: TS_AtteptSetFocus

        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        void TS_AtteptSetFocus(AutomationElement element, Type type, CheckType checkType)
        {
            Comment("Attempt to set focus to the \"{0}\" window and expect the exception of type({1})", element.Current.Name, type.ToString());
            Exception caughtException = null;
            try
            {
                element.SetFocus();
            }
            catch (Exception exception)
            {
                caughtException = exception;
            }

            if (type == null && caughtException != null)
                ThrowMe(checkType, "Should not have gottent the exception({0})", caughtException.GetType().ToString());

            if (type != null && caughtException.GetType() != type)
                ThrowMe(checkType);

            m_TestStep++;
        }
开发者ID:TestStack,项目名称:UIAVerify,代码行数:24,代码来源:ScreenReader.cs

示例5: SelectListItem

 private bool SelectListItem(AutomationElement element, String itemText,
     bool verify = false)
 {
     if (element == null || String.IsNullOrEmpty(itemText))
     {
         throw new XmlRpcFaultException(123,
             "Argument cannot be null or empty.");
     }
     LogMessage("SelectListItem Element: " + element.Current.Name +
         " - Type: " + element.Current.ControlType.ProgrammaticName);
     Object pattern = null;
     AutomationElement elementItem;
     try
     {
         elementItem = utils.GetObjectHandle(element, itemText);
         if (elementItem != null)
         {
             LogMessage(elementItem.Current.Name + " : " +
                 elementItem.Current.ControlType.ProgrammaticName);
             if (verify)
             {
                 bool status = false;
                 if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern,
                     out pattern))
                 {
                     status = ((SelectionItemPattern)pattern).Current.IsSelected;
                 }
                 if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern,
                     out pattern))
                 {
                     LogMessage("ExpandCollapsePattern");
                     element.SetFocus();
                     ((ExpandCollapsePattern)pattern).Collapse();
                 }
                 return status;
             }
             if (elementItem.TryGetCurrentPattern(ScrollItemPattern.Pattern,
                 out pattern))
             {
                 LogMessage("ScrollItemPattern");
                 ((ScrollItemPattern)pattern).ScrollIntoView();
             }
             if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern,
                 out pattern))
             {
                 LogMessage("SelectionItemPattern");
                 //((SelectionItemPattern)pattern).Select();
                 // NOTE: Work around, as the above doesn't seem to work
                 // with UIAComWrapper and UIAComWrapper is required
                 // to Edit value in Spin control
                 return utils.InternalClick(elementItem);
             }
             else if (elementItem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern,
                 out pattern))
             {
                 LogMessage("ExpandCollapsePattern");
                 ((ExpandCollapsePattern)pattern).Expand();
                 element.SetFocus();
                 return true;
             }
             else
             {
                 throw new XmlRpcFaultException(123,
                     "Unsupported pattern.");
             }
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
         if (ex is XmlRpcFaultException)
             throw;
         else
             throw new XmlRpcFaultException(123,
                 "Unhandled exception: " + ex.Message);
     }
     finally
     {
         pattern = null;
         elementItem = null;
     }
     throw new XmlRpcFaultException(123,
         "Unable to find item in the list: " + itemText);
 }
开发者ID:sganesh,项目名称:cobra,代码行数:84,代码来源:Combobox.cs

示例6: TSC_SetFocusVerifyWithEvent

        /// -------------------------------------------------------------------
        /// <summary>
        /// Call SetFocus() and verify the it does get focus by verifying
        /// that the event does occur.  Even if you are not testing for events,
        /// we use the event handler to determine that the element got
        /// the focus.
        /// </summary>
        /// -------------------------------------------------------------------
        internal void TSC_SetFocusVerifyWithEvent(AutomationElement element, CheckType checkType)
        {
            AutomationFocusChangedEventHandler handler = null;
            bool fired = false;

            try
            {
                m_FocusEvents = new ArrayList();
                Comment("Adding AutomationFocusChangedEventHandler");
                handler = new AutomationFocusChangedEventHandler(OnFocusChanged);

                Automation.AddAutomationFocusChangedEventHandler(handler);

                Comment("Calling SetFocus() on " + Library.GetUISpyLook(element));

                // Set the notifier 
                m_NotifiedEvent.Reset();

                element.SetFocus();

                Comment("Wait 1 second for event to happen");
                m_NotifiedEvent.WaitOne(1000, false);
                Comment("Stopped waiting for event to happen");

                Comment("Calling RemoveAutomationFocusChangedEventHandler()");
                Automation.RemoveAutomationFocusChangedEventHandler(handler);
                Comment("Called RemoveAutomationFocusChangedEventHandler()");

                try
                {
                    // Lock this so we don't get anymore events fired.
#pragma warning suppress 6517
                    lock (this)
                    {
                        foreach (AutomationElement tempElement in m_FocusEvents)
                        {
                            AutomationElement el = tempElement;
                            Comment("History of events fired: " + el.Current.Name);

                            // Check to see if any of the elements are the element, or one of the children
                            while (!Automation.Compare(el, AutomationElement.RootElement) && !Automation.Compare(el, element))
                                el = TreeWalker.ControlViewWalker.GetParent(el);

                            if (Automation.Compare(el, element))
                            {
                                fired = true;
                                break;
                            }
                        }
                    }
                }
                finally
                {

                }
            }
            finally
            {

            }
            if (!fired)
                ThrowMe(CheckType.Verification, "Element or one of it's children did not fire the FocusChange event");

            m_TestStep++;
        }
开发者ID:TestStack,项目名称:UIAVerify,代码行数:73,代码来源:TestObject.cs

示例7: pattern_SetFocus

        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void pattern_SetFocus(AutomationElement element, Type expectedException, CheckType checkType)
        {
            string call = "SetFocus()";
            try
            {
                Comment("Calling SetFocus(" + Library.GetUISpyLook(element) + ")");
                element.SetFocus();
                Thread.Sleep(1000);
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;


                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoException(expectedException, call, checkType);

        }
开发者ID:TestStack,项目名称:UIAVerify,代码行数:24,代码来源:TestObject.cs

示例8: SetFocusToElement

 /// <summary>
 /// this method will set focus to the automation element
 /// </summary>
 public static void SetFocusToElement(AutomationElement element)
 {
     if (element != null)
     {
         try
         {
             element.SetFocus();
         }
         catch (Exception ex)
         {
             ApplicationLogger.LogException(ex);
         }
     }
 }
开发者ID:jeffras,项目名称:uiverify,代码行数:17,代码来源:AutomationElementTreeControl.cs

示例9: InsertTextUsingUiAutomation

        /// --------------------------------------------------------------------
        /// <summary>
        ///     Inserts a string into each text control of interest.
        /// </summary>
        /// <param name="element">A text control.</param>
        /// <param name="value">The string to be inserted.</param>
        /// --------------------------------------------------------------------
        private void InsertTextUsingUiAutomation(AutomationElement element,
            string value)
        {
            try
            {
                // Validate arguments / initial setup
                if (value == null)
                    throw new ArgumentNullException(
                        "String parameter must not be null.");

                if (element == null)
                    throw new ArgumentNullException(
                        "AutomationElement parameter must not be null");

                // A series of basic checks prior to attempting an insertion.
                //
                // Check #1: Is control enabled?
                // An alternative to testing for static or read-only controls 
                // is to filter using 
                // PropertyCondition(AutomationElement.IsEnabledProperty, true) 
                // and exclude all read-only text controls from the collection.
                if (!element.Current.IsEnabled)
                {
                    throw new InvalidOperationException(
                        "The control with an AutomationID of "
                        + element.Current.AutomationId
                        + " is not enabled.\n\n");
                }

                // Check #2: Are there styles that prohibit us 
                //           from sending text to this control?
                if (!element.Current.IsKeyboardFocusable)
                {
                    throw new InvalidOperationException(
                        "The control with an AutomationID of "
                        + element.Current.AutomationId
                        + "is read-only.\n\n");
                }


                // Once you have an instance of an AutomationElement,  
                // check if it supports the ValuePattern pattern.
                object valuePattern = null;

                // Control does not support the ValuePattern pattern 
                // so use keyboard input to insert content.
                //
                // NOTE: Elements that support TextPattern 
                //       do not support ValuePattern and TextPattern
                //       does not support setting the text of 
                //       multi-line edit or document controls.
                //       For this reason, text input must be simulated
                //       using one of the following methods.
                //       
                if (!element.TryGetCurrentPattern(
                    ValuePattern.Pattern, out valuePattern))
                {
                    _feedbackText.Append("The control with an AutomationID of ")
                        .Append(element.Current.AutomationId)
                        .Append(" does not support ValuePattern.")
                        .AppendLine(" Using keyboard input.\n");

                    // Set focus for input functionality and begin.
                    element.SetFocus();

                    // Pause before sending keyboard input.
                    Thread.Sleep(100);

                    // Delete existing content in the control and insert new content.
                    SendKeys.SendWait("^{HOME}"); // Move to start of control
                    SendKeys.SendWait("^+{END}"); // Select everything
                    SendKeys.SendWait("{DEL}"); // Delete selection
                    SendKeys.SendWait(value);
                }
                // Control supports the ValuePattern pattern so we can 
                // use the SetValue method to insert content.
                else
                {
                    _feedbackText.Append("The control with an AutomationID of ")
                        .Append(element.Current.AutomationId)
                        .Append((" supports ValuePattern."))
                        .AppendLine(" Using ValuePattern.SetValue().\n");

                    // Set focus for input functionality and begin.
                    element.SetFocus();

                    ((ValuePattern) valuePattern).SetValue(value);
                }
            }
            catch (ArgumentNullException exc)
            {
                _feedbackText.Append(exc.Message);
            }
//.........这里部分代码省略.........
开发者ID:GoodPICK,项目名称:WPF-Samples,代码行数:101,代码来源:MainWindow.cs

示例10: InsertTextIntoElement

        /// <summary>
        /// Inserts the specified string value into the control
        /// referenced by the element
        /// </summary>
        /// <param name="element">the element into which to insert text</param>
        /// <param name="value">text to insert</param>
        public static void InsertTextIntoElement(AutomationElement element, string value)
        {
            if (element == null || value == null)
            {
                return;
            }

            try
            {
                if (!element.Current.IsEnabled || !element.Current.IsKeyboardFocusable)
                {
                    Log.Debug("Control not enabled or keyboard focusable. AutomationID " + element.Current.AutomationId);
                    return;
                }

                object valuePattern;
                if (!element.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
                {
                    element.SetFocus();
                    SendKeys.SendWait(value);
                }
                else
                {
                    element.SetFocus();
                    ((ValuePattern)valuePattern).SetValue(value);
                }
            }
            catch (Exception ex)
            {
                Log.Debug(ex.ToString());
            }
        }
开发者ID:nbsrujan,项目名称:acat,代码行数:38,代码来源:AgentUtils.cs

示例11: SelectItemInComboBox

        private static void SelectItemInComboBox(AutomationElement element, String selectedItemName)
        {            
            // Get the mapped item name.
            String itemName = TestDataInfrastructure.GetControlId(selectedItemName);

            // Set focus to ensure that the object is selected.
            element.SetFocus();

            // Expand the ComboBox using ExpandCollapsePattern.
            ExpandCollapsePattern expandPattern = element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
            expandPattern.Expand();

            // get the desired automation element
            PropertyCondition itemNameCondition = new PropertyCondition(AutomationElement.NameProperty, itemName);
            PropertyCondition itemTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
            AndCondition itemCondition = new AndCondition(itemNameCondition, itemTypeCondition);

            AutomationElement item = element.FindFirst(TreeScope.Descendants, itemCondition);
            if (item != null)
            {
                // select combo box item
                ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
            }
        }
开发者ID:eslahi,项目名称:prism,代码行数:24,代码来源:BuySellModuleFixtureCommon.cs

示例12: SetFocus

 /// <summary>
 /// Set Focus
 /// </summary>
 /// <param name="automationElement">Automation Element object</param>
 /// <returns>successed 1, unsuccesse 0</returns>
 public int SetFocus(AutomationElement automationElement)
 {
     try
     {
         automationElement.SetFocus();
         return 1;
         //this.ReturnResult("1");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return 0;
         //this.ReturnResult(e.Message);
     }
 }
开发者ID:shonwang,项目名称:.Net-UIAutomation-Encapsulate-Again,代码行数:20,代码来源:UIAutomation.cs

示例13: GetUIAutomationWindow

        /// <summary>
        /// This function is used get target window controltype.window from all available windows in desktop.
        /// </summary>
        /// <param name="searchBy">Should be either automationid, text(Name in UI spy),helptext(tooltip over object)  or index</param>
        /// <param name="searchValue">Value for the automationid, text(Name in UI spy) or index passed in searchby parameter.</param>
        /// <param name="index">Ordinal identifier when test object or automation element does not have automationid text, or helptext</param>
        /// <returns></returns>
        public AutomationElement GetUIAutomationWindow(string searchBy, string searchValue)
        {
            bool windowsearch = true;
            if (uiAutomationWindow != null && uiAutomationCurrentParent != null)
            {
                uiAutomationCurrentParent = uiAutomationWindow;
                if ((uiAutomationWindow.Current.Name.ToLower().Contains(searchValue.ToLower())) || (uiAutomationWindow.Current.AutomationId == searchValue.ToLower()))
                {
                    logTofile(_eLogPtah, "[GetUIAutomationWindow]:---> seaching same MasterParentWindow was Avaoided to save time !!  " + uiAutomationWindow.Current.Name.ToLower() + "--" + searchValue.ToLower());
                    windowsearch = false;
                }
            }

            if (windowsearch == true)
            { // start of First IF
                logTofile(_eLogPtah, "[GetUIAutomationWindow]:---> Section :---> searching for Parent Window :  ");
                try
                { //Start of Try
                    logTofile(_eLogPtah, "[GetUIAutomationWindow]:---> Inside Try   ");
                    //    int numwait = 0;
                    switch (searchBy.ToLower())
                    { //Start of Switch
                        case "name":
                        case "text":
                        case "title":
                            { //start of case title
                                logTofile(_eLogPtah, "using  title criteria:  " + searchValue);
                                uiAutomationWindow = GetWindowByName(searchValue);
                                if (uiAutomationWindow == null)
                                {
                                    logTofile(_eLogPtah, "Searching window using collection and contains");
                                    for (var i = 0; i < _Attempts; i++)
                                    {
                                        System.Threading.Thread.Sleep(1);
                                        logTofile(_eLogPtah, "Searched for " + i.ToString() + " times");

                                        uiAutomationWindow = GetWindowByPartialName(searchValue);

                                        if (uiAutomationWindow != null)
                                        {
                                            break;
                                        }
                                    }

                                }
                                if (uiAutomationWindow != null)
                                {
                                    logTofile(_eLogPtah, "window : " + uiAutomationWindow.Current.Name.ToString());
                                }
                                else
                                {
                                    logTofile(_eLogPtah, "Window with Title: " + searchValue + "was not found");
                                }
                                if (UseWhite == true)
                                {
                                    //wpfapp._application = _application;
                                    //try
                                    //{
                                    //    _globalWindow = wpfapp.GetWPFWindow(searchValue.Trim());
                                    //}
                                    //catch (Exception e)
                                    //{
                                    //    logTofile(_eLogPtah, "exception in getwpfwidow was :" + e.Message);
                                    //}
                                }
                                else
                                {
                                    logTofile(_eLogPtah, "White window not initialized");
                                }
                                logTofile(_eLogPtah, "after");

                                //    return uiAutomationWindow;
                                if (uiAutomationWindow != null)
                                {
                                    WindowPattern winpat = (WindowPattern)uiAutomationWindow.GetCurrentPattern(WindowPattern.Pattern);

                                    try   // This is to handle situations when the window cannot be setfocus
                                    {
                                        winpat.SetWindowVisualState(WindowVisualState.Maximized);
                                        uiAutomationWindow.SetFocus();
                                    }
                                    catch (Exception ex)
                                    {
                                        logTofile(_eLogPtah, "[GetUIAutomationWindow]: Focus could not be set adue to  " + ex.Message.ToString());
                                    }
                                }
                                break;
                            } // end of title case
                        case "titlewildcard":
                            { //start of case titlewildcard
                                logTofile(_eLogPtah, "using  title wildcard  criteria:  " + searchValue);
                                for (var i = 0; i < _Attempts; i++)
                                {
//.........这里部分代码省略.........
开发者ID:prasannarhegde2015,项目名称:EJcehck2,代码行数:101,代码来源:UIAutomation.cs

示例14: InsertText

        /// <summary> 
        /// Inserts a string into textbox control
        /// </summary> 
        /// <param name="element">A text control.</param>
        /// <param name="value">The string to be inserted.</param>
        public static void InsertText(AutomationElement element,
                                            string value)
        {
            // Validate arguments / initial setup 
            if (value == null)
                throw new ArgumentNullException(
                    "String parameter must not be null.");

            if (element == null)
                throw new ArgumentNullException(
                    "AutomationElement parameter must not be null");

            // A series of basic checks prior to attempting an insertion. 
            // 
            // Check #1: Is control enabled? 
            // An alternative to testing for static or read-only controls  
            // is to filter using  
            // PropertyCondition(AutomationElement.IsEnabledProperty, true)  
            // and exclude all read-only text controls from the collection. 
            if ( ! element.Current.IsEnabled)
            {
                throw new InvalidOperationException(
                    "The control with an AutomationID of "
                    + element.Current.AutomationId.ToString()
                    + " is not enabled");
            }

            // Once you have an instance of an AutomationElement,   
            // check if it supports the ValuePattern pattern. 
            object valuePattern = null;

            // Control does not support the ValuePattern pattern  
            // so use keyboard input to insert content. 
            // 
            // NOTE: Elements that support TextPattern  
            //       do not support ValuePattern and TextPattern 
            //       does not support setting the text of  
            //       multi-line edit or document controls. 
            //       For this reason, text input must be simulated 
            //       using one of the following methods. 
            //        
            if (!element.TryGetCurrentPattern(
                ValuePattern.Pattern, out valuePattern))
            {
                throw new InvalidOperationException(
                        "The control with an AutomationID of "
                        + element.Current.AutomationId.ToString()
                        + " does not support ValuePattern.");
            }

            // Control supports the ValuePattern pattern so we can  
            // use the SetValue method to insert content. 
            // Set focus for input functionality and begin.
            element.SetFocus();

            ((ValuePattern)valuePattern).SetValue(value);
        }
开发者ID:brogersyh,项目名称:.NET-WindowsUI-AutomationElementsTest,代码行数:62,代码来源:UIAUtility.cs

示例15: SetFocus

 public bool SetFocus(AutomationElement elm)
 {
     elm.SetFocus();
     return true;
 }
开发者ID:OVRLab,项目名称:SeleniumPP,代码行数:5,代码来源:UITree.cs


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