コード例 #1
0
        public void Select(string selection)
        {
            if (selection.Equals(string.Empty))
            {
                foreach (AutomationElement element in _selectionPattern.GetSelection())
                {
                    new SelectionItemPatternWrapper(element).RemoveFromSelection();
                }
            }
            else
            {
                bool found = false;
                _expandCollapsePattern.Expand();

                foreach (AutomationElement listItem in AllItemElements())
                {
                    if (listItem.GetCurrentPropertyValue(AutomationElement.NameProperty).Equals(selection))
                    {
                        new SelectionItemPatternWrapper(listItem).Select();
                        found = true;
                        break;
                    }
                }
                _expandCollapsePattern.Collapse();
                if (!found)
                {
                    throw new FailureToFindException("Failed to find an element in this ComboBox with a value of " + selection +
                                                     ". Please use the ToString() value of the element for selection, or string.Empty to clear the selection. If you want " +
                                                     "to select arbitrary text in an editable ComboBox, please use the EditableComboBox.Text method.");
                }
            }
        }
コード例 #2
0
        public void Select(string item)
        {
            bool found = false;

            if (_expandCollapsePattern.IsAvailable())
            {
                _expandCollapsePattern.Expand();
            }
            foreach (AutomationElement menuItem in AllItemElements())
            {
                if (menuItem.GetCurrentPropertyValue(AutomationElement.NameProperty).Equals(item))
                {
                    new InvokePatternWrapper(menuItem).Invoke();
                    found = true;
                    break;
                }
            }
            if (_expandCollapsePattern.IsAvailable())
            {
                _expandCollapsePattern.Collapse();
            }
            if (!found)
            {
                throw new FailureToFindException("Failed to find an element in this Menu with a value of " + item +
                                                 ". Please use the ToString() value of the element for selection");
            }
        }