UI Automation-WindowPattern

WindowPattern控件模式用于支持传统的图形用户界面(GUI)内提供基于窗口的功能的控件。必须实现此控件模式的控件示例包括顶级应用程序窗口,多文档界面(MDI)子窗口,大小可调的拆分窗格控件,模式对话框以及气球状帮助窗口。可以使用WindowPattern来对window进行操作,例如验证window是否激活,是否最大化,最小化,正常模式以及关闭window等。

示例:

public static void launchCal()

        {

            //Launch Calculator

            Process proc = Process.Start(@"C:/WINDOWS/system32/calc.exe");

            Thread.Sleep(2000);

 

            //Recognize Calculator Window  "Calculator"

            AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Calculator"));

 

            Assert.IsNotNull(window);

            Thread.Sleep(2000);

 

            WindowPattern window1pattern = Utility.UIA.ControlPattern.Windowpattern.GetWindowPattern(window);

            window1pattern.SetWindowVisualState(WindowVisualState.Minimized);

            Thread.Sleep(2000);

 

            window1pattern.SetWindowVisualState(WindowVisualState.Normal);

            Thread.Sleep(2000);}

    public static WindowPattern GetWindowPattern(AutomationElement element)

        {

                object currentPattern;

                if (!element.TryGetCurrentPattern(WindowPattern.Pattern, out currentPattern))

                {

                    throw new Exception(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the WindowPattern.",

                       element.Current.AutomationId, element.Current.Name));

                }

                return currentPattern as WindowPattern;

        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值