MonkeyRunner中点击控件的方法

一、使用控件id去点击的方法

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice

From com.android.monkeyrunner import MonkeyImage

From com.android.monkeyrunner.easy import EasyMonkeyDevice

From com.android.monkeyrunner.easy import By

 

device = MonkeyRunner.waitForConnection()

easy_device = EasyMonkeyDevice(device)

device.startActivity(component = com.android.contacts/com.android.contacts.DialtactsContactsEnteyActivity)

 

easy_device.touch(By.id(id/account_name),MonkeyDevice.DOWN_AND_UP)

 

二、使用坐标去点击的方法

 

获取坐标的方法:

1.使用手机的指针位置来实现

系统设置---开发者选项---勾选指针位置,然后开启后,点击界面需要点击的控件。

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

device=MonkeyRunner.waitForConnection(1.0,'82627d4b')
device.startActivity(component=com.android.contacts/com.android.contacts.DialactsContactsEntryActivity)

MonkeyRunner.sleep(3)

device.touch(470,659,MonkeyDevice.DOWN_AND_UP)
for i in range(1,999999):
MonkeyRunner.sleep(4)

device.touch(1136,361,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(5)

device.touch(1196,363,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(4)

device.touch(150,412,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(4)
print i
else:
print('end')

 

转载,还未实验过。

<!--EndFragment-->

你可能感兴趣的:(MonkeyRunner)