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

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

  • 相关阅读:
    Redis和Memcache的区别
    j2EE框架collection
    总结乐观锁和悲观锁
    lunix,命令集锦
    遍历Map集合的方法
    arrayList和vector的区别
    python借助zookeeper实现分布式服务(二)
    python借助zookeeper实现分布式服务(一)
    zookeeper常用命令
    python实现事件驱动模型
  • 原文地址:https://www.cnblogs.com/qixue/p/2995552.html
Copyright © 2011-2022 走看看