Python pywinauto自动化测试

应用启动

import os
from time import sleep
from pywinauto.application import Application
# 进入到应用程序目录,启动程序
os.chdir(path)
app = Application(backend="uia").start(app_path)
'''
元素信息
Control Identifiers:

Dialog - '登陆'    (L735, T320, R1185, B720)
['Dialog', '登陆', '登陆Dialog']
child_window(title="登陆", control_type="Window")
   | Static - '登录名'    (L784, T516, R864, B534)
   | ['Static', '登录名Static', '登录名', 'Static0', 'Static1']
   | child_window(title="登录名", auto_id="tbkName", control_type="Text")
   | 
   | ComboBox - ''    (L872, T511, R1072, B539)
   | ['登录名ComboBox', 'ComboBox']
   | child_window(auto_id="cbUser", control_type="ComboBox")
      | Static - '密 码'    (L784, T551, R864, B569)
   | ['密 码', 'Static2', '密 码Static']
   | child_window(title="密 码", control_type="Text")
   | 
   | Edit - ''    (L872, T546, R1072, B574)
   | ['Edit2', '密 码Edit']
   | child_window(auto_id="pbPassWord", control_type="Edit")
      | Button - '登 录'    (L870, T608, R1070, B640)
   | ['Button4', '登 录', '登 录Button', '登 录0', '登 录1']
   | child_window(title="登 录", auto_id="btnLogin", control_type="Button")
   |    | 
   |    | Static - '登 录'    (L953, T614, R987, B633)
   |    | ['登 录Static', '登 录2', 'Static5']
   |    | child_window(title="登 录", control_type="Text")
   									'''

元素定位

'''
	登录元素定位
	密码输入框定位
	登录按钮定位
	'''
user_input = app['登录Dialog']['ComboBox']
password_input = app['登录Dialog']['密 码Edit']
login_Button = app['登录Dialog']['登 录Button']

模拟操作

'''
	输入账号
	输入密码
	点击登录按钮
	'''
user_input.type_keys('admin')
password_input.type_keys('123456')
login_Button.click()

其他扩展

# 导入鼠标类,通过横坐标、纵坐操作元素
from pywinauto import mouse
mouse.click(button='left', coords=(106, 31))

'''
跨平台模块模拟真实用户的鼠标事件

pywinauto.mouse.click(button='left', coords=(0, 0))

单击指定的坐标

pywinauto.mouse.double_click(button='left', coords=(0, 0))

双击指定的坐标

pywinauto.mouse.move(coords=(0, 0))

移动鼠标

pywinauto.mouse.press(button='left', coords=(0, 0))

按下鼠标按钮

pywinauto.mouse.release(button='left', coords=(0, 0))

释放鼠标按钮

pywinauto.mouse.right_click(coords=(0, 0))

右键单击指定的坐标

pywinauto.mouse.scroll(coords=(0, 0), wheel_dist=1)

滚动鼠标滚轮

pywinauto.mouse.wheel_click(coords=(0, 0))

鼠标中键单击指定的坐标
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值