UI Automation-SelectItemPattern
来源:互联网 发布:mac spss许可证 编辑:程序博客网 时间:2024/05/18 03:46
感谢原作者的分享 http://blog.csdn.net/lynn_yan/article/category/611860
SelectItemPattern用于选择容器控件如列表框和组合框中的各个项。
支持SlectItemPattern的控件有ListView,ListBox,RadioButton,GridView等。
SelectItemPattern的三个重要方法:
· AddToSelection:将当前元素添加到所选项的集合;
· RemoveFromSelction:从选定项的集合中移除当前元素。
· Select:取消所有以选中的项,然后选择当前元素。
可以通过Current属性的IsSelected属性来判断AutomationElement是否被selected.
public static SelectionItemPattern GetSelectionItemPattern(AutomationElement element)
{
object currentPattern = null;
if (!element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out currentPattern))
{
throw new Exception(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the SelectionItemPattern.",
element.Current.AutomationId, element.Current.Name));
}
return currentPattern as SelectionItemPattern;
}
public static void select(AutomationElement element)
{
SelectionItemPattern selectitempattern = GetSelectionItemPattern(element);
selectitempattern.Select();
}
示例:
public static void launchCal()
{
//Launch Calculator
Process proc = Process.Start("calc");
Thread.Sleep(2000);
//Recognize Calculator Window "Calculator"
AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, newPropertyCondition(AutomationElement.NameProperty, "Calculator"));
//Assert.IsNotNull(window);
Thread.Sleep(2000);
//Expand view button
//Recognize view menu
AutomationElement view = window.FindFirst(TreeScope.Descendants, newPropertyCondition(AutomationElement.NameProperty, "View"));
Assert.IsNotNull(view);
Thread.Sleep(2000);
Utility.UIA.ControlPattern.ExpandCollapsepattern.Expand(view);
Thread.Sleep(2000);
//Recognize menu item "Programmer"
AutomationElement Programmer = window.FindFirst(TreeScope.Descendants, newPropertyCondition(AutomationElement.NameProperty, "Programmer"));
Thread.Sleep(2000);
InvokePattern programmerpattern=Utility.UIA.ControlPattern.Invokepattern.GetInvokePattern(Programmer);
programmerpattern.Invoke();
Thread.Sleep(2000);
//Recoginze Oct Radio Button "Oct"
AutomationElement oct=window.FindFirst(TreeScope.Descendants,newPropertyCondition(AutomationElement.NameProperty,"Oct"));
Thread.Sleep(2000);
SelectionItemPatternoctpattern=Utility.UIA.ControlPattern.SelectionItempattern.GetSelectionItemPattern(oct);
if (octpattern.Current.IsSelected.ToString() == "False")
{
octpattern.Select();
}
- UI Automation-SelectItemPattern
- UI Automation-SelectItemPattern
- UI Automation
- UI Automation Introduction.
- UI Automation(一)
- UI Automation-InvokePattern
- UI Automation-ValuePattern
- UI Automation-ExpandCollapsePattern
- UI Automation test
- UI Automation-ScrollPattern
- UI Automation-TogglePattern
- UI automation - .net
- UI Automation-WindowPattern
- UI Automation-GridPattern
- UI Automation-TablePattern
- UI Automation-RangeValuePattern
- UI Automation-TransformPattern
- UI Automation-MultipleViewPattern
- 一行代码创建AlertView
- UI Automation-ScrollPattern
- HLJU14级寒假集训之最短路专场
- iPhone消息推送机制实现与探讨
- python selenium安装
- UI Automation-SelectItemPattern
- ios Sqlite数据库增删改查基本操作
- Sort Colors
- UI Automation-ExpandCollapsePattern
- UI Automation-ValuePattern
- UI Automation-InvokePattern
- Windows Phone8.1中SD卡文件的读取写入方法汇总
- ArcSDE10.1 连接SQL Server 2008
- Redis研究(九)—有序集合类型 2