Exemplo n.º 1
0
 public static IUIAutomationElement xtSetValue2(this IUIAutomationElement element, string value)
 {
     _LegacyIAccessiblePattern = (IUIAutomationLegacyIAccessiblePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId);
     _LegacyIAccessiblePattern.SetValue(value);
     Thread.Sleep(100);
     element.SetFocus();
     Thread.Sleep(100);
     return(element);
 }
Exemplo n.º 2
0
 /// <summary>
 /// This method will attempt to set the LegacyIAccessible Value of an element and then press TAB.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="value"></param>
 public static IUIAutomationElement xtSetValue(this IUIAutomationElement element, string value)
 {
     _LegacyIAccessiblePattern = (IUIAutomationLegacyIAccessiblePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId);
     _LegacyIAccessiblePattern.SetValue(value);
     Thread.Sleep(100);
     element.SetFocus();
     Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.TAB);
     return(element);
 }
Exemplo n.º 3
0
 public static IUIAutomationElement xtFocus(this IUIAutomationElement element)
 {
     try
     {
         element.SetFocus();
     }
     catch (Exception e) { }
     Thread.Sleep(100);
     return(element);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Focuses the Element.
 /// </summary>
 public Element SetFocus()
 {
     try
     {
         IUIElement.SetFocus();
     }
     catch (COMException e) { }
     Thread.Sleep(100);
     return(this);
 }
Exemplo n.º 5
0
        public static IUIAutomationElement xtClickCenterOfBounds(this IUIAutomationElement element)
        {
            try { element.SetFocus(); } catch (Exception e) { }
            var   rectangle = element.CurrentBoundingRectangle;
            Point center    = new Point();

            center.X = rectangle.left + ((rectangle.right - rectangle.left) / 2);
            center.Y = rectangle.top + ((rectangle.bottom - rectangle.top) / 2);
            Mouse.Instance.Location = center;
            Thread.Sleep(250);
            Mouse.Instance.Click(MouseButton.Left, center);
            return(element);
        }
        public SetResult TrySet(string value)
        {
            if (!DoesApply())
            {
                return(SetResult.NotApplicable);
            }
            _element.SetFocus();

            // Pause before sending keyboard input. SendKeys is pretty picky about this
            Thread.Sleep(100);

            // Delete existing content in the control and insert new content.
            SendKeys.SendWait("^a{DEL}");
            Thread.Sleep(500);
            SendKeys.SendWait(value);
            Thread.Sleep(500); // workaround for timing issue with SendKeys
            return(SetResult.Success);
        }
Exemplo n.º 7
0
 public override void Invoke()
 {
     _automationElement.SetFocus();
 }
Exemplo n.º 8
0
        public static void xtSelectFromComboBox(this IUIAutomationElement element, string Option)
        {
            var childrenOfCombobox = element.xtGetAllChildren();
            IUIAutomationElement listItemToSelect = null;

            bool IsInsideTable = element.xtGetRelative(RelativeType.Parent).CurrentLocalizedControlType == "dataitem";

            //	Seeing if the intended Option to Select even exists
            bool found = false;

            for (int i = 0; i < childrenOfCombobox.Length; i++)
            {
                if (childrenOfCombobox.GetElement(i).CurrentName == Option)
                {
                    found            = true;
                    listItemToSelect = (IUIAutomationElement)childrenOfCombobox.GetElement(i);
                    break;
                }
            }
            if (!found)
            {
                Console.WriteLine($"List Item is not an Option!!! ComboBox Name: [{element.CurrentName}] - ComboBox ID: [{element.CurrentAutomationId}] - List Item Selection: [{Option}] .");
                throw new Exception($"List Item is not an Option!!! ComboBox Name: [{element.CurrentName}] - ComboBox ID: [{element.CurrentAutomationId}] - List Item Selection: [{Option}] .");
            }

            //	If intended list item is already selected - just skip everything - no need
            if (listItemToSelect.xtIsItemSelected())
            {
                return;
            }

            //	Seeing if a blank option exists
            bool blankOptionExists = false;

            for (int i = 0; i < childrenOfCombobox.Length; i++)
            {
                if (childrenOfCombobox.GetElement(i).CurrentName == " ")
                {
                    blankOptionExists = true;
                    break;
                }
            }

            // Block to Complete selection if the combo box is inside a table row
            if (IsInsideTable)
            {
                try { element.xtScrollIntoView(); } catch (Exception e) { }
                Thread.Sleep(50);
                element.xtFocus();
                Thread.Sleep(50);
                element.xtClickCenterOfBounds();

                for (int i = 0; i < (childrenOfCombobox.Length + 2); i++)
                {
                    Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.UP);
                }
                for (int i = 0; i < (childrenOfCombobox.Length + 2); i++)
                {
                    if (listItemToSelect.xtIsItemSelected())
                    {
                        break;
                    }
                    Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.DOWN);
                }
                goto czCheckpoint;
            }


            //	Block to complete the ComboBox Selection
            if (blankOptionExists)
            {
                Thread.Sleep(50);
                element.SetFocus();
                Thread.Sleep(50);
                Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SPACE);
                element.xtCollapse();

                for (int i = 0; i < childrenOfCombobox.Length + 2; i++)
                {
                    Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.DOWN);
                    if (listItemToSelect.xtIsItemSelected())
                    {
                        break;
                    }
                }
            }
            else if (!blankOptionExists)
            {
                Thread.Sleep(50);
                element.SetFocus();
                Thread.Sleep(50);

                element.SetFocus();

                for (int i = 0; i < (childrenOfCombobox.Length + 2); i++)
                {
                    Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.UP);
                }
                for (int i = 0; i < (childrenOfCombobox.Length + 2); i++)
                {
                    Thread.Sleep(50);
                    if (listItemToSelect.xtIsItemSelected())
                    {
                        break;
                    }
                    Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.DOWN);
                }
            }


czCheckpoint:

            if (!listItemToSelect.xtIsItemSelected())
            {
                Console.WriteLine($"ComboBox list item was not properly selected!!! Element Name: [{element.CurrentName}] - Element ID: [{element.CurrentAutomationId}] - List Item Selection: [{Option}] .");
                throw new Exception($"ComboBox list item was not properly selected!!! Element Name: [{element.CurrentName}] - Element ID: [{element.CurrentAutomationId}] - List Item Selection: [{Option}] .");
            }

            Keyboard.Instance.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.TAB);
            Thread.Sleep(100);
        }
Exemplo n.º 9
0
 public void SetFocus()
 {
     IUIAutomationElement.SetFocus();
 }