zoukankan      html  css  js  c++  java
  • UIA: Choose item in Combobox

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

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

  • 相关阅读:
    Sudoku Solver [LeetCode]
    Populating Next Right Pointers in Each Node [LeetCode]
    Binary Tree Level Order Traversal [LeetCode]
    Clone Graph [LeetCode]
    Merge k Sorted Lists [LeetCode]
    Combinations [LeetCode]
    021 面向对象 一
    给图片加点料
    质数
    ex10 找出藏在字符串中的“密码”
  • 原文地址:https://www.cnblogs.com/qixue/p/2995552.html
Copyright © 2011-2022 走看看