【Python + ATX基于uiaotumator2】之Android—APP自动化简易例子
上代码:
import uiautomator2 as u2from time import sleep
d = u2.connect_usb('608ad0fe')
#打开小卖
# d(text=u"小卖安全").click()
d.app_start("cn.sqm.citymine_safety")
sleep(0.2)
#输入用户名
d(resourceId="cn.sqm.citymine_safety:id/et_login_id").send_keys("ceshi07")
d.click(0.924, 0.607)
#输入密码
d(resourceId="cn.sqm.citymine_safety:id/et_login_password").set_text("111111")
d.click(0.924, 0.607)
#点击登录按钮
d(resourceId="cn.sqm.citymine_safety:id/btn_login").click()
#点击发起任务
d(className="android.widget.ImageView", instance=25).click()
#选择任务类型:日常检查
d(resourceId="cn.sqm.citymine_safety:id/tv_select_task_type").click()
sleep(0.5)
d(className="android.view.View").drag_to(0.506, 0.759, duration=0.5)
d(resourceId="cn.sqm.citymine_safety:id/btn_confirm").click()
#检查单位:IOS开发
d(resourceId="cn.sqm.citymine_safety:id/tv_select_inspection_area").click()
d(resourceId="cn.sqm.citymine_safety:id/item_tv_next_level").click()
d(resourceId="cn.sqm.citymine_safety:id/item_tv_department").click()
#隐患类型:其他
d(resourceId="cn.sqm.citymine_safety:id/tv_select_hidden_danger_type").click()
d(className="android.view.View").drag_to(0.506, 0.759, duration=0.5)
d(text='确定').click()
#隐患描述
d(resourceId="cn.sqm.citymine_safety:id/et_hidden_danger_description").set_text("其他问题")
d.click(0.924, 0.607)
#照片:1
d(resourceId="cn.sqm.citymine_safety:id/iv_choose_photos").click()
d(text=u"手机相册").click()
d(resourceId="cn.sqm.citymine_safety:id/v_selected", className="android.widget.ImageView", instance=10).click()
d(resourceId="cn.sqm.citymine_safety:id/done").click()
#违反制度:违反员工行为规范
d(resourceId="cn.sqm.citymine_safety:id/iv_add_violation").click()
d(resourceId="cn.sqm.citymine_safety:id/item_tv_content_violation", text=u"违反员工行为规范").click()
d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click()
#向上滑动拖拽
d(className="android.widget.LinearLayout").drag_to(0.498, 0.00, duration=0.5)
#整改期限:选择9月1号
d(resourceId="cn.sqm.citymine_safety:id/tv_please_the_rectification_date").click()
for i in range(2):
d(resourceId="cn.sqm.citymine_safety:id/day").drag_to(0.82, 0.8, duration=0.5)
d(text='确定').click()
#协同人员
list = ["开发02",]
d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name").click()
for i in range(len(list)):
d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name", text=list[i]).click()
d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click()
#单位负责人
d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name", className="android.widget.TextView", instance=len(list)+1).click()
for i in range(2):
d(resourceId="cn.sqm.citymine_safety:id/lv_area_manager").click()
d(resourceId="cn.sqm.citymine_safety:id/item_tv_department", text=u"区域07").click()
d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click()
#返回首页
sleep(0.5)
d.click(0.063, 0.068)
#点击我的
d(resourceId="cn.sqm.citymine_safety:id/rb_single_center").click()
#退出账号
d(text="安全退出账号").click()
#返回首页home
d.press("home")
#測試完成關閉軟件
d.service("uiautomator").stop()
以上是 【Python + ATX基于uiaotumator2】之Android—APP自动化简易例子 的全部内容, 来源链接: utcz.com/z/388786.html