聪明的猴子

import uiautomation,random

#找到计算器这个窗口
# window = uiautomation.WindowControl(searchDepth=1,Name="计算器")
# print(window)

#判断窗口是否存在

# if window.Exists():
#     print("找到")
    #置顶窗口
    # window.SetTopmost(isTopmost=True)

    # 最大化
    # window.Maximize()

    # 让窗口激活(从最小化返回桌面)
    # window.SetActive()

    # 返回左上角和右下角的坐标
    # res = window.BoundingRectangle
    # x=[res.left,res.right]
    # y=[res.top,res.bottom]

    # button = uiautomation.ButtonControl(searchDepth=1,Name="7")
    # button.Click()

def test():
    tester = uiautomation.WindowControl(searchDepth=1,Name="计算器")
    if tester.Exists():
        uiautomation.ButtonControl(searchDepth=4,Name="7").Click()
        uiautomation.ButtonControl(searchDepth=4,Name="加").Click()
        uiautomation.ButtonControl(searchDepth=4,Name="3").Click()
        uiautomation.ButtonControl(searchDepth=4,Name="等于").Click()
        res=uiautomation.TextControl(searchDepth=4,ControlType="ControlType.Text",AutomationId="158")
        # print(type(res.Name))
        if res.Name=="10":
            print("成功")

def show():
    tester = uiautomation.WindowControl(searchDepth=1,Name="计算器")
    rad1=random.randint(1,9)
    rad2=random.randint(1,9)
    methods=["加","减","乘","除"]
    rad_mtd=random.randint(0,3)
    if tester.Exists():
        uiautomation.ButtonControl(searchDepth=4,Name=str(rad1)).Click()
        uiautomation.ButtonControl(searchDepth=4,Name=methods[rad_mtd]).Click()
        uiautomation.ButtonControl(searchDepth=4,Name=str(rad2)).Click()
        uiautomation.ButtonControl(searchDepth=4,Name="等于").Click()
        res = uiautomation.TextControl(searchDepth=4,AutomationId="158")
        # print(type(res.Name))
        if rad_mtd==0:
            if res.Name=="%d"%(rad1+rad2):
                print("成功")
            else:
                print("失败")
            print("%d%s%d=%d" % (rad1, methods[rad_mtd], rad2,rad1+rad2))
        elif rad_mtd==1:
            if res.Name=="%d"%(rad1-rad2):
                print("成功")
            else:
                print("失败")
            print("%d%s%d=%d" % (rad1, methods[rad_mtd], rad2, rad1 - rad2))
        elif rad_mtd==2:
            if res.Name=="%d"%(rad1*rad2):
                print("成功")
            else:
                print("失败")
            print("%d%s%d=%d" % (rad1, methods[rad_mtd], rad2, rad1 * rad2))
        elif rad_mtd==3:
            if round(float(res.Name),4)==round(rad1/rad2,4):
                print("成功")
            else:
                print("失败")
            print("%d%s%d=%f" % (rad1, methods[rad_mtd], rad2, rad1 / rad2))
        else:
            print("出错啦!!!")

if __name__ == '__main__':
    # test()
    for i in range(10):
        show()

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值