我们可以借助Android SDK自的uiautomatorviewer查看元素,这就要求手机必须以USB的方式连接PC,我前面使用的是WIFI连接进行连接的。所以,openatx提供了另外一个工具weditor 来解决这个问题。 GitHub地址:https://github.com/openatx/weditor (1)、安装:
cls.d.app_stop("com.addcn.android.house591")
cls.d(resourceId="com.addcn.android.house591:id/ad_banner").click()
d.xpath("//*[@content-desc='分享']").click()
d(text="Add new").count 或者 len(d(text="Add new")) 得知数目之后,我们可以通过索引去定位
也可以遍历
for view in d(text="Add new"): view.info
import cv2 image = d.screenshot( format = ' opencv') cv2.imwrite( ' home.jpg '图像)#获取原始JPEG数据 imagebin = d.screenshot(格式= '原始') 打开( “ some.jpg ”, “ WB ”).WRITE(imagebin) 1、单击
2、长按
# swipe from (sx, sy) to (ex, ey)d.swipe(sx, sy, ex, ey) # swipe from (sx, sy) to (ex, ey) with 10 stepsd.swipe(sx, sy, ex, ey, steps=10)
# drag from (sx, sy) to (ex, ey)d.drag(sx, sy, ex, ey) # drag from (sx, sy) to (ex, ey) with 10 stepsd.drag(sx, sy, ex, ey, steps=10)
(7)获取对象信息和状态 1、 d(text="Settings").exists #如果存在则为True,否则为假 or d.exists(text="Settings") # 进一步使用 d(text="Settings").exists(timeout=3) d(text="Settings").info 3、获取/设置/清除可编辑字段的文本(例如,EditText小部件) d(text = “ Settings ”).get_text() # get widget text d(text = “ Settings ”).set_text(“ My text ... ”) #设置文本 d(text = “ Settings ”).clear_text( ) #清除文字、 (8)系统常用按键 # press home key d.press.home() # press back key d.press.back() # the normal way to press back key d.press("back")----亲测可用 # press keycode 0x07('0') with META ALT(0x02) on d.press(0x07, 0x02)
六、使用经验 python3 -m weditor |
|