Inheritance: ICollection, IEnumerable
        private void FindCurrentWindows()
        {
            metlWindows = MeTL.GetAllMainWindows(2, true);

            ownerWindow = null;
            participantWindow = null;
        }
        public void SelectItem(string item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                var matchingIndex = -1;
                AutomationElement itemToSelect = null;

                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    var expand = (BasePattern) basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree,
                                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
                            for (var x = 0; x < availableOptions.Count; x++)
                            {
                                if (item == availableOptions[x].Current.Name)
                                {
                                    itemToSelect = availableOptions[x];
                                }
                            }
                            if (itemToSelect != null)
                            {
                                var selectPattern =
                                    (SelectionItemPattern) itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                                try
                                {
                                    selectPattern.Select();
                                }
                                catch (Exception e)
                                {
                                    TestBase.Log("An exception was handled by PurpleDropDown Class: " + e.Message);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItem(item);
                }
            }
        }
 public void MyTestInitialize()
 {
     // Get all children of the desktop for our target collection
     CacheRequest cacheReq = new CacheRequest();
     cacheReq.Add(AutomationElement.NameProperty);
     cacheReq.Add(AutomationElement.NativeWindowHandleProperty);
     using (cacheReq.Activate())
     {
         this.testColl = AutomationElement.RootElement.FindAll(
             TreeScope.Children,
             Condition.TrueCondition);
         Assert.IsNotNull(this.testColl);
         Assert.IsTrue(this.testColl.Count > 0);
     }
 }
        public void CloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            new ApplicationPopup(metlWindow.AutomationElement).Quit();

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
示例#5
0
 private TreeNode Generate_Tree(TreeNode root,AutomationElementCollection UIElems,Element.UIType ElemType,AutomationElement Target=null)
 {
     TreeNode returnNode = null;
     foreach (AutomationElement each in UIElems)
     {
         Element.Element eachNode = new Element.Element(each.Current.Name, ElemType, each);
         TreeNode eachTreeNode = new TreeNode(eachNode.Name);
         eachTreeNode.Tag = eachNode;
         root.Nodes.Add(eachTreeNode);
         if ((Target != null) && (Target == each))
         {
             returnNode = eachTreeNode;
         }
     }
     return returnNode;
 }
        public void CloseAllInstances()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();

            foreach (AutomationElement window in metlWindows)
            {
                var metlWindow = new UITestHelper(UITestHelper.RootElement, window);
                metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
                metlWindow.Find();

                new ApplicationPopup(metlWindow.AutomationElement).Quit();

                UITestHelper.Wait(TimeSpan.FromSeconds(2));
            }

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
示例#7
0
 /// <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));
 }
        public void SelectItem(string item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                int matchingIndex = -1;
                AutomationElement itemToSelect = null;

                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    ExpandCollapsePattern expand = (BasePattern) basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
                            for (int x = 0; x < availableOptions.Count; x++)
                            {
                                if (item == availableOptions[x].Current.Name)
                                {
                                    itemToSelect = availableOptions[x];
                                }
                            }
                            if (itemToSelect != null)
                            {
                                SelectionItemPattern selectPattern = (SelectionItemPattern) itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                                selectPattern.Select();
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItem(item);
                }
            }
        }
        public void LogoutAndCloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            var logoutAndExit = new UITestHelper(metlWindow);
            logoutAndExit.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_LOGOUT_AND_EXIT_BACKNAV_BUTTON));

            logoutAndExit.WaitForControlExist();
            logoutAndExit.AutomationElement.Invoke(); 

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
示例#10
0
        public void DoOperations()
        {
            Process[] p = Process.GetProcessesByName("pcsws");

            //System.Windows.Automation.AutomationElement t = WinFormAdapter.GetAEFromHandle(p[0].MainWindowHandle);
            System.Windows.Automation.AutomationElement _0 = AutomationElement.FromHandle(p[0].MainWindowHandle);

            //System.Windows.Automation.AutomationElement t1 = WinFormAdapter.GetAEOnChildByName(t, "Sesión A - [24 x 80]");
            //System.Windows.Automation.AutomationElement t1 = t.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Inicio de sesión de IBM i"));

            //TODO: Obtener por tipo de elemento (Tipo.Edit)
            //Al tener el mismo nombre tanto el label como el textbox de un campo, toma los dos, al parecer el segundo siempre es el textbox....
            System.Windows.Automation.AutomationElementCollection _0_Descendants_1 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "ID de usuario:"));
            WinFormAdapter.SetText(_0_Descendants_1[1], "BFPJUARUI");

            System.Windows.Automation.AutomationElementCollection _0_Descendants_2 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Contraseña:"));
            WinFormAdapter.SetText(_0_Descendants_2[1], "BFPJUARUI2");

            WinFormAdapter.ClickElement(WinFormAdapter.GetAEOnDescByName(_0, "Aceptar"));
        }
示例#11
0
        private string GetCurrentUrl(AutomationElementCollection toolbars)
        {
            try
            {
                foreach (AutomationElement toolbar in toolbars)
                {
                    var combobox = toolbar.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ComboBox));

                    if (combobox != null)
                    {
                        var edit = combobox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                        return base.GetUrl(edit.GetCurrentPropertyValue(LegacyIAccessiblePattern.ValueProperty) as string);
                    }
                }
            }
            catch
            { }

            return null;
        }
        public void AttachToProcess()
        {
            var win1 = MeTL.StartProcess();
            var win2 = MeTL.StartProcess();

            var metlWindow1 = new UITestHelper();
            var metlWindow2 = new UITestHelper();

            var propertyExpression = new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW);
            metlWindow1.SearchProperties.Add(propertyExpression);
            metlWindow2.SearchProperties.Add(propertyExpression);
            metlWindow1.WaitForControlExist();
            metlWindow2.WaitForControlExist();

            Thread.Sleep(3000);

            if (windows == null)
                windows = MeTL.GetAllMainWindows();

            Assert.IsTrue(windows.Count == 2, "Expected two instances to be running.");
            Assert.IsNotNull(windows, "Could not find a process named MeTL.  Have you started an instance (it can be clickonce)");
        }
示例#13
0
        protected static AutomationElement FindNode(AutomationElementCollection nodes, string[] splitPath, int depth) {
            for (int i = 0; i < nodes.Count; i++) {
                var node = nodes[i];
                var name = node.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;

                if (name.Equals(splitPath[depth], StringComparison.CurrentCulture)) {
                    if (depth == splitPath.Length - 1) {
                        return node;
                    }

                    // ensure the node is expanded...
                    try {
                        EnsureExpanded(node);
                    } catch (InvalidOperationException) {
                        // handle race w/ items being removed...
                        Console.WriteLine("Failed to expand {0}", splitPath[depth]);
                    }
                    return FindNode(node.FindAll(TreeScope.Children, Condition.TrueCondition), splitPath, depth + 1);
                }
            }
            return null;
        }
示例#14
0
        public void Test()
        {
            StartProces();

             var mainWindowAutomationElement = AutomationElement.FromHandle(_process.MainWindowHandle);

             _automationElements = mainWindowAutomationElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);

             StructureChangedEventHandler structureChangedEventHandler = OnStructureChange;
             Automation.AddStructureChangedEventHandler(mainWindowAutomationElement, TreeScope.Subtree,
            structureChangedEventHandler);

             var random = new Random();

             while (!_process.HasExited && ProcessIsActiveWindow())
             {
            var randomAutomationElement = _automationElements[random.Next(_automationElements.Count - 1)];

            try
            {
               Console.WriteLine($"Name: {randomAutomationElement.Current.Name} ClassName: {randomAutomationElement.Current.ClassName}");

               if (CheckElementIsInvalid(randomAutomationElement))
                  continue;

               var location = randomAutomationElement.Current.BoundingRectangle.Location;

               SetCursorPos((int) location.X, (int) location.Y);

               Click((int) MouseEvent.MouseEventLeftDown, 0, 0, 0, 0);
               Click((int) MouseEvent.MouseEventLeftUp, 0, 0, 0, 0);
            }
            catch (ElementNotAvailableException)
            {
               Console.WriteLine("ElementNotAvailableException");
            }
             }
        }
示例#15
0
        public static AutomationElement[] NativeArrayToManaged(UIA2Automation automation, UIA.AutomationElementCollection nativeElements)
        {
            if (nativeElements == null)
            {
                return(new AutomationElement[0]);
            }
            var retArray = new AutomationElement[nativeElements.Count];

            for (var i = 0; i < nativeElements.Count; i++)
            {
                var nativeElement     = nativeElements[i];
                var automationElement = automation.WrapNativeElement(nativeElement);
                retArray[i] = automationElement;
            }
            return(retArray);
        }
示例#16
0
 protected override AutomationElement ActiveTab(IntPtr hWnd, out AutomationElementCollection tabItems)
 {
     throw new NotImplementedException();
 }
示例#17
0
 public override AutomationElement SelectedTab(AutomationElementCollection tabItems)
 {
     throw new NotImplementedException();
 }
示例#18
0
文件: Program.cs 项目: Kimicz20/Kimi
 //获取多选框元素 index数组表示选择的的哪几项,rows是多选列表的各个选项
 public static void MutlSelect(int[] indexes, AutomationElementCollection rows, bool isSelectAll)
 {
     object multiSelect;
        if (isSelectAll)
        {
        for (int i = 1; i < rows.Count - 1; i++)
        {
            if (rows[i].TryGetCurrentPattern(SelectionItemPattern.Pattern, out multiSelect))
            {
                (multiSelect as SelectionItemPattern).AddToSelection();
            }
        }
        }
        else
        {
        if (indexes.Length > 0)
        {
            for (int j = 0; j < indexes.Length; j++)
            {
                int tempIndex = indexes[j];
                if (rows[tempIndex].TryGetCurrentPattern(SelectionItemPattern.Pattern, out multiSelect))
                {
                    (multiSelect as SelectionItemPattern).AddToSelection();
                }
            }
        }
        }
 }
示例#19
0
 private string[] GetListItemValue(AutomationElementCollection listItems)
 {
     string strItems = "";
     foreach (AutomationElement item in listItems)
     {
         var textObj = TreeWalker.RawViewWalker.GetFirstChild(item) ?? item;
         string value = textObj.Current.Name;
         strItems += value + "|";
     }
     return strItems.Substring(0, strItems.Length - 1).Split('|');
 }
示例#20
0
        private void OnStructureChange(object sender, StructureChangedEventArgs e)
        {
            Console.WriteLine($"OnStructureChange {e.StructureChangeType}, {e.EventId}, {e.GetRuntimeId()}");

             var automationElement = AutomationElement.FromHandle(_process.MainWindowHandle);
             _automationElements = automationElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);
        }
示例#21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="property"></param>
 public RadioButton(AutomationElement parent)
 {
     _radioButtonCollection = Helper.ExtractElementByControlType(parent, ControlType.RadioButton);
     Helper.ValidateArgumentNotNull(_radioButtonCollection, "Radio Collection Button AutomationElement ");
 }
示例#22
0
        /// --------------------------------------------------------------------
        /// <summary>
        ///     Handles the click event for the Start App button.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        /// --------------------------------------------------------------------
        private void btnStartApp_Click(object sender, RoutedEventArgs e)
        {
            _targetWindow = StartTargetApp(_filePath);

            if (_targetWindow == null)
            {
                return;
            }

            Feedback("Target started.");

            var clientLocationTop = Client.Top;
            var clientLocationRight = Client.Left + Client.Width + 100;
            var transformPattern =
                _targetWindow.GetCurrentPattern(TransformPattern.Pattern)
                    as TransformPattern;
            transformPattern?.Move(clientLocationRight, clientLocationTop);

            // Get required control patterns 
            //
            // Once you have an instance of an AutomationElement for the target 
            // obtain a WindowPattern object to handle the WindowClosed event.
            try
            {
                var windowPattern =
                    _targetWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
            }
            catch (InvalidOperationException)
            {
                Feedback("Object does not support the Window Pattern");
                return;
            }

            // Register for an Event
            // 
            // The WindowPattern allows you to programmatically 
            // manipulate a window. 
            // It also exposes a window closed event. 
            // The following code shows an example of listening 
            // for the WindowClosed event.
            //
            // To intercept the WindowClosed event for our target application
            // you define an AutomationEventHandler delegate.
            var targetClosedHandler =
                new AutomationEventHandler(OnTargetClosed);

            // Use AddAutomationEventHandler() to add this event handler.
            // When listening for a WindowClosed event you must either scope 
            // the event to the automation element as done here, or cast 
            // the AutomationEventArgs in the handler to WindowClosedEventArgs 
            // and compare the RuntimeId of the automation element that raised 
            // the WindowClosed event to the automation element in the 
            // class member data.
            Automation.AddAutomationEventHandler(
                WindowPattern.WindowClosedEvent,
                _targetWindow,
                TreeScope.Element,
                targetClosedHandler);

            SetClientControlProperties(false, true);

            // Get our collection of interesting controls.
            _textControls = FindTextControlsInTarget();
        }
示例#23
0
 private static void PrintAutomationElements(AutomationElementCollection elements)
 {
     foreach (var c in elements) {
         try {
             var ae = (c as AutomationElement);
             PrintLine(PadToLength(ae.Current.ClassName) + " " + PadToLength(ae.Current.AutomationId) + " " + ae.Current.Name);
         } catch (Exception) { }
     }
 }
示例#24
0
        public AutomationElement GetElementPriority(AutomationElementCollection inCollection)
        {
            //gather the current elements in the GUI.
            List<ElementEntry> currentElements = new List<ElementEntry> { };
            foreach (AutomationElement iter in inCollection)
            {
                if (SkipElement(iter))
                    continue;

                var elementLog =
                    from myElem in mElementTracker
                    where (ElementIsEntry(iter, myElem))
                    select myElem;

                if (elementLog.Count() == 0)
                { //new element
                    mElementTracker.Add(new ElementEntry { Name = iter.Current.Name, AutomationId = iter.Current.AutomationId, mControlType = iter.Current.ControlType, Priority = 100 });
                }
                if (elementLog.Count() <= 1)
                { //recover old element
                    currentElements.Add(elementLog.First());
                }
                else
                { //multiple matches to element. Add more criteria.
                    Debug.Assert(false);
                }
            }

            //sort current elements by rank.
            //currentElements.Sort(PrioritizeElementEntries);
            foreach (var elem in currentElements.OrderBy(p => p.Priority))
            {
                StreamManager.WriteLine(elem.Name + " " + elem.AutomationId + " " + elem.Priority);
            }

            int sumPriority = 0;
            foreach (ElementEntry elem in currentElements)
            {
                sumPriority += elem.Priority;
            }

            //randomly choose a ElementEntry weighted by priority.
            AutomationElement returnElement = null;
            int randomVal = rand.Next(sumPriority);
            int count = randomVal;
            foreach (ElementEntry myEntry in currentElements)
            {
                if (count < myEntry.Priority && returnElement == null)
                {
                    myEntry.Priority--;
                    var elementLog =
                    from AutomationElement myElem in inCollection
                    where (ElementIsEntry(myElem, myEntry))
                    select myElem;
                    StreamManager.WriteLine("CHOOSE: " + elementLog.First().Current.Name + elementLog.First().Current.AutomationId);
                    myEntry.Priority = 100;
                    returnElement = elementLog.First();
                }
                else
                {
                    count -= myEntry.Priority;
                    myEntry.Priority++;
                }

                    var updateLog =
                    from myElem in mElementTracker
                    where (myElem.Name == myEntry.Name)
                    select myElem;

                    updateLog.First().Priority = myEntry.Priority;
            }

            return returnElement;
        }
示例#25
0
 public TextBox(AutomationElement parentElement, ControlType type)
 {
     _textBoxCollection = Helper.ExtractElementByControlType(parentElement, ControlType.Edit);
     Helper.ValidateArgumentNotNull(_textBoxCollection, "TestBox Collection AutomationElement ");
 }
示例#26
0
        public void SelectItemByPosition(int item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                //int matchingIndex = -1;
                //AutomationElement itemToSelect = null;
                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    var expand = (BasePattern) basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree,
                                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

                            if (item < availableOptions.Count && availableOptions[item - 1] != null)
                            {
                                var selectPattern =
                                    (SelectionItemPattern)
                                        availableOptions[item - 1].GetCurrentPattern(SelectionItemPattern.Pattern);
                                try
                                {
                                    selectPattern.Select();
                                }
                                catch (Exception e)
                                {
                                    //There is a timeout exception on the filter data panel
                                    TestBase.Log("An exception was handled by PurpleDropDown Class: " + e.Message);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItemByPosition(item);
                }
            }
        }
示例#27
0
 private void KeyboardToSelectListItem(AutomationElementCollection listItems, int targetItemIndex)
 {
     string defaultValue = this.DisplayText;
     if (defaultValue == "")
     {
         SendKeys.SendWait("{DOWN " + targetItemIndex+1 + "}");
     }
     else
     {
         string[] arrListValue = GetListItemValue(listItems);
         int i = 0;
         for (; i < arrListValue.Count(); i++)
         {
             if (arrListValue[i] == defaultValue)
             {
                 break;
             }
         }
         if (i - targetItemIndex < 0)
             SendKeys.SendWait("{DOWN " + (targetItemIndex - i) + "}");
         else
             SendKeys.SendWait("{UP " + (i - targetItemIndex) + "}");
     }
     Thread.Sleep(500);
     SendKeys.SendWait("{ENTER}");
 }
示例#28
0
文件: ListItem.cs 项目: RussBaz/PTVS
 public ListItem(AutomationElement element, ListView parent) : base(element) { 
     _parent = parent;
     _columns = FindAllByControlType(ControlType.Text);
 }
示例#29
0
 public Treeitem(AutomationElement parentelement,ControlType type)
 {
     treeitemcollection = Helper.ExtractElementByControlType(parentelement,ControlType.TreeItem);
     Helper.ValidateArgumentNotNull(treeitemcollection,"treeitem collection automationelement");
 }
示例#30
0
        public void SelectItemByPosition(int item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                //int matchingIndex = -1;
                //AutomationElement itemToSelect = null;
                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    ExpandCollapsePattern expand = (BasePattern)basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree,
                                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

                            if (item < availableOptions.Count && availableOptions[item - 1] != null)
                            {
                                SelectionItemPattern selectPattern =
                                    (SelectionItemPattern) availableOptions[item - 1].GetCurrentPattern(SelectionItemPattern.Pattern);
                                selectPattern.Select();
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItemByPosition(item);
                }
            }
        }
示例#31
0
 public AutomationElement GetElementRandom(AutomationElementCollection inSet)
 {
     if (inSet.Count == 0)
         return null;
     int index = rand.Next(0, inSet.Count - 1);
     if (SkipElement(inSet[index]))
         return null;
     return inSet[index];
 }
示例#32
0
 /// --------------------------------------------------------------------
 /// <summary>
 ///     Finds the selection and selection item controls of interest
 ///     and initializes necessary event listeners.
 /// </summary>
 /// <remarks>
 ///     Handles the special case of two Selection controls being returned
 ///     for a ComboBox control.
 /// </remarks>
 /// --------------------------------------------------------------------
 private void CompileTargetControls()
 {
     var condition =
         new PropertyCondition(
             AutomationElement.IsSelectionPatternAvailableProperty, true);
     // A ComboBox is an aggregate control containing a ListBox 
     // as a child. 
     // Both the ComboBox and its child ListBox support the 
     // SelectionPattern control pattern but all related 
     // functionality is delegated to the child.
     // For the purposes of this sample we can filter the child 
     // as we do not need to display the redundant information.
     var andCondition = new AndCondition(
         condition,
         new NotCondition(
             new PropertyCondition(
                 AutomationElement.ClassNameProperty, "ComboLBox")));
     TargetControls =
         _targetApp.FindAll(TreeScope.Children |
                            TreeScope.Descendants, andCondition);
     _clientApp.EchoTargetControls();
 }