uiautomation的使用

1.通过父节点获取对应的子节点

import uiautomation as auto
 
def find_control(control, compare=lambda c: True, maxDepth: int = 0xFFFFFFFF):
    """
    返回单个Control对象
    control:父节点,查找父节点下的子孙节点
    compare:自定义过滤函数,函数只返回True、False,当返回为True时,会保留节点
    maxDepth:查询深度,默认查找control的所有子孙节点,maxDepth=1时,查询control的第一个子节点,maxDepth=2时,查询第一个子节点的子节点,依次类推
    """
 
    def temp_func(control, compare, depth=0):
 
        if depth >= maxDepth:
            return None
        #获取底下的孩子结点
        child_list = control.GetChildren()
        #循环查询孩子结点,查到对应的结点则返回该结点,如果不存在则往下一层查询
        for child in child_list:
            if compare(child):
                return child
            else:
                child = temp_func(child, compare, depth + 1)
                if child:
                    return child
 
    return temp_func(control, compare)
 
root = auto.GetRootControl()
#获取钉钉控制窗口
dd_win = root.WindowControl(Name="钉钉",ClassName="StandardFrame_DingTalk")
#激活钉钉窗口
dd_win.SetActive()
#关闭钉钉窗口
dd_win_min = find_control(dd_win,lambda a:a.GetLegacyIAccessiblePattern().Name == "关闭" and a.Name == "关闭")
dd_win_min.Click()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值