• UIAutomation学习入门


    .界面的自动化操作

    .Ui自动化测试

    .软件外挂

    .Win32基础知识

    a.Win32中一切元素皆窗口,窗口之间有父子关系。整个桌面是一个“根窗口”。

    b.进程:

    根据进程id拿到进程对象Process process = Process.GetProcessById(processId);

    启动一个进程:Process process = Process.Start(exe路径);

    杀死一个进程process.Kill()

    .UIAutonation基础

    1、需要添加对UIAutomationClient、 UIAutomationProvider、 UIAutomationTypes的引用

    2AutomationElement.RootElement是窗口根元素

    AutomationElement.FromHandle(IntPtr hwnd)从窗口句柄拿到AutomationElement对象。

    3、遍历:

    mainElement.FindAll(TreeScope.Descendants,

    new PropertyCondition(AutomationElement.ClassNameProperty, "TLabeledEdit"));

    TreeScope.Descendants代表递归从所有子孙元素中递归查找;如果是从直接子节点查找,则使用TreeScope.Children

    Condition是过滤条件,可以根据类名等查找,如果是不指定查询条件则使用Condition.True Condition

    FindFirst是查到第一个。

    4、点击按钮、设置文本、读取文本使用Pattern来实现。不是所有Pattern都支持

    1)设置控件的值

    ValuePattern 

    valuePattern = (ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern);

    valuePattern.SetValue("rupeng.com");

    2)得到文本控件的值

    TextPattern 

    valuePattern = (TextPattern)element.GetCurrentPattern(TextPattern.Pattern);

    string v=  valuePattern.DocumentRange.GetText(-1);

    3)调用控件,比如点击按钮

    var clickPattern = (InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern);

    clickPattern.Invoke();

  • 相关阅读:
    设计模式:生产者消费者模式
    图解SSH原理
    监听Google Player下载并获取包名等信息
    android targetSdkVersion>=26收不到广播的处理
    ant property file刷新不及时
    maven的pom文件报错: must be "pom" but is "jar"
    AJAX其实就是一个异步网络请求
    String、StringBuffer、StringBuilder的区别
    Properties、ResourceBundle
    JavaWeb--Listener
  • 原文地址:https://www.cnblogs.com/miaosha5s/p/4993321.html
Copyright © 2020-2023  润新知