码迷,mamicode.com
首页 > 其他好文 > 详细

自动化测试(二)

时间:2020-11-17 12:24:13      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:type   att   out   box   current   exp   ring   idp   sele   

实例1:找到已知名称的窗口

AutomationElement desktop = AutomationElement.RootElement;
string wndName="XXX";
Wnd = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty,wndName));

 

实例2:找到窗口中一个显示为“开始”的文本Label

string ControlName="开始";
            var lbStart = Wnd.FindFirst(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text),new PropertyCondition(AutomationElement.NameProperty,ControlName)));

 

实例3:有一个id为calendar的ComboBox,选择其中的July项

            string ComboItemName = "July";
            //找到id为calendar的ComboBox
            AutomationElement calendar = Wnd.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "calendar"));
            
            //展开
            ExpandCollapsePattern ecPattern = (ExpandCollapsePattern)calendar.GetCurrentPattern(ExpandCollapsePattern.Pattern);
            ecPattern.Expand();

            //找到名称为July的项
            var typeCond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
            
            AutomationElementCollection items = calendar.FindAll(TreeScope.Descendants, typeCond);
            AutomationElement itemToSelect = items[6];

            Object selectPattern = null;
            if (itemToSelect.TryGetCurrentPattern(SelectionItemPattern.Pattern, out selectPattern))
            {
                ((SelectionItemPattern)selectPattern).Select();
            }

 

自动化测试(二)

标签:type   att   out   box   current   exp   ring   idp   sele   

原文地址:https://www.cnblogs.com/noigel/p/13958186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!