public override void DoExecute()
        {
            AutomationElement     a = UiElement.AutomationElement;
            ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            var cbxEditItems = UiElement.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxEditItem"));

            switch (PlaybackObject.action)
            {
            case "SetText":
                try
                {
                    var Editor = a.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "PART_Editor"));
                    ((ValuePattern)Editor.GetCurrentPattern(ValuePattern.Pattern)).SetValue(PlaybackObject.text);
                    expandCollapsePattern.Collapse();
                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            case "Select":
                try
                {
                    if (cbxEditItems[PlaybackObject.itemIndex].AutomationElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "CheckEdit")) != null)
                    {
                        var checkBox = cbxEditItems[PlaybackObject.itemIndex].FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "CheckEdit"));
                        checkBox.AsCheckBox().Click();
                        SendKeys.SendWait("{ENTER}");
                    }
                    else
                    {
                        cbxEditItems[PlaybackObject.itemIndex].AutomationElement.SelectionItemPattern().Select();
                        expandCollapsePattern.Collapse();
                    }
                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            default:
                Result = false;
                break;
            }

            //expandCollapsePattern.Collapse();
        }
Beispiel #2
0
        public override void DoExecute()
        {
            AutomationElement a = UiElement.AutomationElement;

            Console.WriteLine(a.Current.AutomationId);

            ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            var comboBoxEditItemCondition = new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxEditItem");
            var listItems = a.FindAll(TreeScope.Subtree, comboBoxEditItemCondition);//It can only get one item in the list (the first one).
            var testItem  = listItems[listItems.Count - 1];
            int index1    = 0;
            int index     = 0;

            foreach (AutomationElement item in listItems)
            {
                foreach (AutomationElement itemChild in item.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock")))
                {
                    if (itemChild.Current.Name == Control.text)
                    {
                        //testItem=
                    }
                }


                index++;
            }

            (testItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select();
            expandCollapsePattern.Collapse();
        }
Beispiel #3
0
        public static AutomationElement SetComboBox(this AutomationElement parent, string name, string value)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

            if (box == null)
            {
                throw new Exception("ComboBox '" + name + "' not found");
            }
            if (!box.Current.IsEnabled)
            {
                throw new Exception("ComboBox '" + name + "' is not enabled");
            }

            ExpandCollapsePattern p = (ExpandCollapsePattern)box.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            p.Expand();
            Thread.Sleep(250);

            AutomationElement item = box.FindFirstWithRetries(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.NameProperty, value),
                                                                                                      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)));

            if (item == null)
            {
                throw new Exception("ComboBoxItem '" + value + "' not found in combo box '" + name + "'");
            }

            SelectionItemPattern si = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern);

            si.Select();

            p.Collapse();
            return(box);
        }
Beispiel #4
0
        public static void SetSelectedComboBoxItem(AutomationElement
                                                   comboBox, string item)
        {
            AutomationPattern automationPatternFromElement =
                GetSpecifiedPattern(comboBox,
                                    "ExpandCollapsePatternIdentifiers.Pattern");

            ExpandCollapsePattern expandCollapsePattern =
                comboBox.GetCurrentPattern(automationPatternFromElement) as
                ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            expandCollapsePattern.Collapse();

            AutomationElement listItem =
                comboBox.FindFirst(TreeScope.Subtree, new
                                   PropertyCondition(AutomationElement.NameProperty, item));

            automationPatternFromElement = GetSpecifiedPattern(listItem,
                                                               "SelectionItemPatternIdentifiers.Pattern");

            SelectionItemPattern selectionItemPattern =
                listItem.GetCurrentPattern(automationPatternFromElement) as
                SelectionItemPattern;

            selectionItemPattern.Select();
        }
Beispiel #5
0
        //</Snippet1102>

        ///--------------------------------------------------------------------
        /// <summary>
        /// Handles the ExpandCollapse click event.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        ///--------------------------------------------------------------------
        private void ExpandCollapse_Click(object sender, RoutedEventArgs e)
        {
            Button clientButton      = sender as Button;
            ExpandCollapsePattern ec = clientButton.Tag as ExpandCollapsePattern;

            if (ec == null)
            {
                return;
            }
            ExpandCollapseState currentState = ec.Current.ExpandCollapseState;

            try
            {
                if ((currentState == ExpandCollapseState.Collapsed) ||
                    (currentState == ExpandCollapseState.PartiallyExpanded))
                {
                    ec.Expand();
                    statusText.Text = "TreeItem expanded.";
                }
                else if (currentState == ExpandCollapseState.Expanded)
                {
                    ec.Collapse();
                    statusText.Text = "TreeItem collapsed.";
                }
            }
            catch (InvalidOperationException)
            {
                // The current state of the element is LeafNode.
                Output("Unable to expand or collapse the element.");
            }
        }
Beispiel #6
0
        public override void perform(ComponentPrx component, Ice.Current context__)
        {
            AutomationElement     element     = WGComponent.fromId(component.getId());
            ExpandCollapsePattern patternMenu =
                element.GetCurrentPattern(
                    ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            // Pattern is not available for this component
            if (patternMenu == null)
            {
                // TODO: Log message
                return;
            }

            ExpandCollapseState state = patternMenu.Current.ExpandCollapseState;

            if (state == ExpandCollapseState.Expanded)
            {
                patternMenu.Collapse();
            }
            else if (state == ExpandCollapseState.PartiallyExpanded ||
                     state == ExpandCollapseState.Collapsed)
            {
                patternMenu.Expand();
            }
        }
Beispiel #7
0
        private void SetSelection(string option)
        {
            if ((comboBoxElement != null) &&
                (comboBoxElement.Current.IsEnabled))
            {
                AutomationElement sel = null;

                ExpandCollapsePattern expandPattern
                    = (ExpandCollapsePattern)comboBoxElement
                      .GetCurrentPattern(
                          ExpandCollapsePattern.Pattern);

                expandPattern.Expand();

                CacheRequest cacheRequest = new CacheRequest();
                cacheRequest.Add(AutomationElement.NameProperty);
                cacheRequest.TreeScope = TreeScope.Element
                                         | TreeScope.Children;

                AutomationElement comboboxItems
                    = comboBoxElement.GetUpdatedCache(
                          cacheRequest);

                foreach (AutomationElement item
                         in comboboxItems.CachedChildren)
                {
                    if (item.Current.Name == "")
                    {
                        CacheRequest cacheRequest2 = new CacheRequest();
                        cacheRequest2.Add(AutomationElement.NameProperty);
                        cacheRequest2.TreeScope = TreeScope.Element
                                                  | TreeScope.Children;

                        AutomationElement comboboxItems2
                            = item.GetUpdatedCache(cacheRequest);

                        foreach (AutomationElement item2
                                 in comboboxItems2.CachedChildren)
                        {
                            if (item2.Current.Name == option)
                            {
                                sel = item2;
                            }
                        }
                    }
                }

                if (sel != null)
                {
                    SelectionItemPattern select =
                        (SelectionItemPattern)sel.GetCurrentPattern(
                            SelectionItemPattern.Pattern);

                    select.Select();
                }
                expandPattern.Collapse();
            }
            SetForegroundWindow(this.Handle);
        }
        public static void Collapse(this AutomationElement expandControl)
        {
            //check if the buttonControl is indeed a handle to a button-based control
            ExpandCollapsePattern expColPattern = ValidateExpandCollapseControl(expandControl);

            //Collapse
            expColPattern.Collapse();
        }
Beispiel #9
0
        /// <summary>
        /// Collapses the specified control.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Collapse(AutomationElement control)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)CommonUIAPatternHelpers.CheckPatternSupport(ExpandCollapsePattern.Pattern, control);

            control.SetFocus();
            pat.Collapse();
            return(0);
        }
Beispiel #10
0
        public static bool Collapse(AutomationElement item)
        {
            ExpandCollapsePattern pattern = item.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            pattern.Collapse();

            return(true);
        }
        private void GetLooksListFromPro7UI()
        {
            cboLooks.Items.Clear();

            // Setup a condition and find the first menu named "Screens"
            Condition conditionScreensMenu = new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem),
                new PropertyCondition(AutomationElement.NameProperty, "Screens")
                );
            AutomationElement aeScreensMenu = aeProPresenter.FindFirst(TreeScope.Descendants, conditionScreensMenu);

            // If Screens menu is not currently expanded then expand it - as WPF menuItems need to be expanded to explore them.
            ExpandCollapsePattern expandPattern = aeScreensMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            if (expandPattern.Current.ExpandCollapseState != ExpandCollapseState.Expanded)
            {
                expandPattern.Expand();
            }

            // Let's get all the sub menuitems of the Screens menu...
            AutomationElementCollection aecScreensMenuItems = aeScreensMenu.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem));

            // If UI changes in design, this code will break - it assumes Looks menu is at index 2 of the screens menu items.
            // The third sub menuitem of the Screens menu is the Live:Look menu (well, at least in Pro7.4.1 - this may change in future)
            AutomationElement liveMenu = aecScreensMenuItems[2];

            // Grab the name of the current look
            String currentLookName = liveMenu.FindAll(TreeScope.Descendants, Condition.TrueCondition)[1].Current.Name;

            // If Live:Look menu is not currently expanded then expand it - as WPF menuItems need to be expanded to explore them.
            ExpandCollapsePattern expandPattern2 = liveMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            if (expandPattern2.Current.ExpandCollapseState != ExpandCollapseState.Expanded)
            {
                expandPattern2.Expand();
            }

            // Let's get all the sub menuitems of the Live:Look menu (this is where we finally get a list of the looks)
            aeLiveMenuItems = liveMenu.FindAll(TreeScope.Children, Condition.TrueCondition);

            // - to get names, grab child textblock of each menuItem)
            AutomationElementCollection aeLiveMenuItems2 = aeLiveMenuItems[0].FindAll(TreeScope.Descendants, Condition.TrueCondition);

            // Add each look to a list....(ready to invoke later when clicked)
            foreach (AutomationElement liveMenuItem in aeLiveMenuItems)
            {
                this.cboLooks.Items.Add(liveMenuItem.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)).Current.Name);
            }

            if (currentLookName.Length > 0)
            {
                this.cboLooks.SelectedItem = currentLookName;
            }

            // Collapse Menu - we are done exploring..
            expandPattern2.Collapse();
            expandPattern.Collapse();
        }
Beispiel #12
0
        public static void Collapse(AutomationElement element)
        {
            ExpandCollapsePattern currentPattern = AutomationPatternHelper.GetExpandCollapsePattern(element);

            if (currentPattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded)
            {
                currentPattern.Collapse();
            }
        }
Beispiel #13
0
        /// <summary>
        /// Collapses the selected item.  The item must support the expand/collapse pattern.
        /// </summary>
        /// <param name="node"></param>
        public static void Collapse(AutomationElement node)
        {
            CheckNullElement(node);
            ExpandCollapsePattern pat = (ExpandCollapsePattern)node.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            if (pat.Current.ExpandCollapseState != ExpandCollapseState.Collapsed)
            {
                pat.Collapse();
            }
        }
Beispiel #14
0
        public void Collapse(bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Collapse {0}.", this.NameAndType));
            }

            ExpandCollapsePattern ecp = (ExpandCollapsePattern)element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            ecp.Collapse();
        }
Beispiel #15
0
        public void SelectItem(string name)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();

            var item = Element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name));

            ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();

            pat.Collapse();
        }
Beispiel #16
0
        public override void DoExecute()
        {
            AutomationElement a = UiElement.AutomationElement;

            ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            var components = a.FindAll(TreeScope.Subtree, Condition.TrueCondition);

            var comboBoxEditItemCondition = new PropertyCondition(AutomationElement.ClassNameProperty, "ListBoxItem");
            var listItems = a.FindAll(TreeScope.Subtree, comboBoxEditItemCondition);//It can only get one item in the list (the first one).

            foreach (AutomationElement a5 in listItems)
            {
                (a5.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select();
            }

            switch (PlaybackObject.action)
            {
            case "SetText":
                try
                {
                    ((ValuePattern)a.GetCurrentPattern(ValuePattern.Pattern)).SetValue(PlaybackObject.text);

                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            case "Select":
                try
                {
                    (listItems[PlaybackObject.itemIndex].GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select();
                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            default:
                Result = false;
                break;
            }

            expandCollapsePattern.Collapse();
        }
        private void ExpandCollapsePatternController()
        {
            ExpandCollapsePattern expandCollapsePattern = (ExpandCollapsePattern)PatternObject;

            if (MethodType == 1)
            {
                expandCollapsePattern.Expand();
            }
            else if (MethodType == 2)
            {
                expandCollapsePattern.Collapse();
            }
        }
        private void signalChange(String name)
        {
            System.Windows.Automation.Condition textConditionOne = new PropertyCondition(AutomationElement.AutomationIdProperty, "TXcombo");
            AutomationElement     textOne      = testWindow.FindFirst(TreeScope.Descendants, textConditionOne);
            ExpandCollapsePattern valuetextOne = textOne.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            valuetextOne.Expand();
            AutomationElement    listItem = textOne.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, name));
            AutomationPattern    automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern");
            SelectionItemPattern selectionItemPattern         = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern;

            selectionItemPattern.Select();
            valuetextOne.Collapse();
        }
Beispiel #19
0
        public void CollapseTreeNode(string treepath)
        {
            AutomationElement e = _openitem(this._condition.AutomationElement, treepath, false);

            try
            {
                ExpandCollapsePattern mexpand = (ExpandCollapsePattern)e.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                mexpand.Collapse();
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Beispiel #20
0
        private void buttonGet_Click(
            object sender,
            EventArgs e)
        {
            if ((comboBoxElement != null) &&
                (comboBoxElement.Current.IsEnabled))
            {
                ExpandCollapsePattern expandPattern
                    = (ExpandCollapsePattern)comboBoxElement
                      .GetCurrentPattern(
                          ExpandCollapsePattern.Pattern);

                expandPattern.Expand();

                listBox1.Items.Clear();

                CacheRequest cacheRequest = new CacheRequest();
                cacheRequest.Add(AutomationElement.NameProperty);

                cacheRequest.TreeScope = TreeScope.Element
                                         | TreeScope.Children;

                AutomationElement comboboxItems = comboBoxElement
                                                  .GetUpdatedCache(cacheRequest);

                foreach (AutomationElement item
                         in comboboxItems.CachedChildren)
                {
                    if (item.Current.Name == "")
                    {
                        CacheRequest cacheRequest2 = new CacheRequest();
                        cacheRequest2.Add(AutomationElement.NameProperty);
                        cacheRequest2.TreeScope = TreeScope.Element
                                                  | TreeScope.Children;

                        AutomationElement comboboxItems2
                            = item.GetUpdatedCache(cacheRequest);

                        foreach (AutomationElement item2
                                 in comboboxItems2.CachedChildren)
                        {
                            listBox1.Items.Add(item2.Current.Name);
                        }
                    }
                }
                expandPattern.Collapse();
            }
            GetSelection();
        }
        // </Snippet101>

        // <Snippet102>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Programmatically expand or collapse a menu item.
        /// </summary>
        /// <param name="menuItem">
        /// The target menu item.
        /// </param>
        ///--------------------------------------------------------------------
        private void ExpandCollapseMenuItem(
            AutomationElement menuItem)
        {
            if (menuItem == null)
            {
                throw new ArgumentNullException(
                          "AutomationElement argument cannot be null.");
            }

            ExpandCollapsePattern expandCollapsePattern =
                GetExpandCollapsePattern(menuItem);

            if (expandCollapsePattern == null)
            {
                return;
            }

            if (expandCollapsePattern.Current.ExpandCollapseState ==
                ExpandCollapseState.LeafNode)
            {
                return;
            }

            try
            {
                if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded)
                {
                    // Collapse the menu item.
                    expandCollapsePattern.Collapse();
                }
                else if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed ||
                         expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.PartiallyExpanded)
                {
                    // Expand the menu item.
                    expandCollapsePattern.Expand();
                }
            }
            // Control is not enabled
            catch (ElementNotEnabledException)
            {
                // TO DO: error handling.
            }
            // Control is unable to perform operation.
            catch (InvalidOperationException)
            {
                // TO DO: error handling.
            }
        }
Beispiel #22
0
 public void ExpandCollapse()
 {
     STAHelper.Invoke(
         delegate() {
         ExpandCollapsePattern expandCollapse = ExpandCollapsePattern;
         if (expandCollapse.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
         {
             expandCollapse.Expand();
         }
         else
         {
             expandCollapse.Collapse();
         }
     }
         );
 }
        internal void pattern_Collapse(Type expectedException, CheckType checkType)
        {
            string call = "Collapse()";

            try
            {
                m_pattern.Collapse();
                System.Threading.Thread.Sleep(1);
            }
            catch (Exception actualException)
            {
                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoException(expectedException, call, checkType);
        }
        public void SelectItem(string name)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();
            try {
                var item = Element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name));

                if (item == null)
                {
                    throw new ElementNotAvailableException(name + " is not in the combobox");
                }
                ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
            } finally {
                pat.Collapse();
            }
        }
        public void ClickDropDown(AutomationElement ExpandCollapseItem, bool Expand = true)
        {
            Thread.Sleep(1000);
            ExpandCollapsePattern expandCollapsePattern = ExpandCollapseItem.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            if (expandCollapsePattern != null)
            {
                if (Expand)
                {
                    expandCollapsePattern.Expand();
                }
                else
                {
                    expandCollapsePattern.Collapse();
                }
            }
        }
        //public static void SetSelectedComboBoxItem(this AutomationElement comboBox, string item)
        //{
        //    AutomationPattern automationPatternFromElement = GetSpecifiedPattern(comboBox, "ExpandCollapsePatternIdentifiers.Pattern");

        //    ExpandCollapsePattern expandCollapsePattern = comboBox.GetCurrentPattern(automationPatternFromElement) as ExpandCollapsePattern;

        //    expandCollapsePattern.Expand();
        //    expandCollapsePattern.Collapse();

        //    AutomationElement listItem = comboBox.FindFirst(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty, item));

        //    automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern");

        //    SelectionItemPattern selectionItemPattern = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern;

        //    selectionItemPattern.Select();
        //}
        #endregion
        #region 2nd Way to select combobox item
        public static void SetSelectedComboBoxItem(this AutomationElement comboBoxElement, string item)
        {
            if (comboBoxElement == null)
            {
                throw new Exception("Combo Box not found");
            }

            //Get the all the list items in the ComboBox


            //Expand the combobox
            ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            expandPattern.Expand();
            expandPattern.Collapse();
            AutomationElementCollection comboboxItem = comboBoxElement.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
            int i = 0;

            //try to get patterns
            //foreach(AutomationElement cbcItem in comboboxItem)
            //{
            //    foreach (AutomationPattern ap in cbcItem.GetSupportedPatterns())
            //    {
            //        MessageBox.Show(ap.ProgrammaticName);

            //    }
            //}
            foreach (AutomationElement cbxItem in comboboxItem)
            {
                if (cbxItem.FindFirst(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition).Current.Name == item)
                {
                    break;
                }
                i++;
            }
            //Index to set in combo box
            AutomationElement itemToSelect = comboboxItem[i];

            //Finding the pattern which need to select
            SelectionItemPattern selectPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);

            selectPattern.Select();
        }
        public void ExpandCollapsePatternTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
            {
                // Find a well-known combo box
                AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
                                                                 new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
                Assert.IsNotNull(combo);

                ExpandCollapsePattern expando = (ExpandCollapsePattern)combo.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Collapsed);
                expando.Expand();
                System.Threading.Thread.Sleep(100 /* ms */);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Expanded);
                expando.Collapse();
                System.Threading.Thread.Sleep(100 /* ms */);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Collapsed);
            }
        }
 private void paletteChange(String name)
 {
     try
     {
         System.Windows.Automation.Condition textConditionOne = new PropertyCondition(AutomationElement.AutomationIdProperty, "Palettecombo");
         AutomationElement     textOne      = testWindow.FindFirst(TreeScope.Descendants, textConditionOne);
         ExpandCollapsePattern valuetextOne = textOne.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
         valuetextOne.Expand();
         AutomationElement    listItem = textOne.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, name));
         AutomationPattern    automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern");
         SelectionItemPattern selectionItemPattern         = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern;
         selectionItemPattern.Select();
         valuetextOne.Collapse();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Couldn't change palette to " + name);
     }
 }
Beispiel #29
0
        public string GetSelectedItemName()
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();
            try {
                var items = Element.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ListBoxItem"));

                foreach (AutomationElement item in items)
                {
                    if (((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Current.IsSelected)
                    {
                        return(item.Current.Name);
                    }
                }
                return(null);
            } finally {
                pat.Collapse();
            }
        }
Beispiel #30
0
        public static bool CollapseMenuItem(AutomationElement element)
        {
            if (ControlType.MenuItem != element.Current.ControlType)
            {
                return(false);
            }
            object expandCollapsePatternObject          = null;
            ExpandCollapsePattern expandCollapsePattern = null;

            if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out expandCollapsePatternObject))
            {
                Console.WriteLine("ExpandMenuItem TryGetCachedPattern Current {0}", element.Current.Name);
                expandCollapsePattern = expandCollapsePatternObject as ExpandCollapsePattern;
            }
            else if (element.TryGetCachedPattern(ExpandCollapsePattern.Pattern, out expandCollapsePatternObject))
            {
                Console.WriteLine("ExpandMenuItem TryGetCurrentPattern Cache {0}", element.Cached.Name);
                expandCollapsePattern = expandCollapsePatternObject as ExpandCollapsePattern;
            }

            if (null != expandCollapsePattern && ExpandCollapseState.LeafNode != expandCollapsePattern.Current.ExpandCollapseState)
            {
                try
                {
                    if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded ||
                        expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.PartiallyExpanded)
                    {
                        expandCollapsePattern.Collapse();
                        Thread.Sleep(500);
                    }
                    return(true);
                }
                // Object doesn't support the ExpandCollapsePattern control pattern.
                catch (InvalidOperationException)
                {
                    Console.WriteLine("FindRelevantElements InvalidOperationException {0}", element.Current.Name);
                }
            }
            return(false);
        }