Use UI Automation, to choose an item in Combobox, code like this:

using System.Windows.Automation;

        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();
        }

        private static AutomationPattern GetSpecifiedPattern(AutomationElement element, string patternName)
        {
            AutomationPattern[] supportedPattern = element.GetSupportedPatterns();

            foreach (AutomationPattern pattern in supportedPattern)
            {
                if (pattern.ProgrammaticName == patternName)
                    return pattern;
            }

            return null;
        }

在网上找到这段代码, 发现能用呢! 哈啊哈

相关文章:

  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-11-14
  • 2022-03-08
  • 2022-12-23
  • 2021-05-30
  • 2021-10-25
猜你喜欢
  • 2021-08-26
  • 2021-07-13
  • 2022-12-23
  • 2021-06-09
  • 2021-10-29
  • 2022-12-23
  • 2021-07-07
相关资源
相似解决方案