欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

[android]monkeyrunner得id查寻方法

更新时间: 2014-01-05 02:35:27 责任编辑: Author_N1

 

[Android]Monkeyrunner得id查找方法
该方法是莹莹同学发现得,先感谢。

实现方式如下:
from com.android.monkeyrunner import MonkeyRunner as MR  
from com.android.monkeyrunner import MonkeyDevice as MD  
from com.android.monkeyrunner import MonkeyImage as MI  
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By  

device=MR.waitForConnection(10)  
if device:  
 print("Connect device successful!")  
else:  
 print("Connect device failed!")  
device=EasyMonkeyDevice(device)  
device.installPackage("D:\\MonkeyRunnerDemo\\Apps\\estore.apk")  
device.startActivity(component="com.eshore.ezone/.StartActivity")  
MR.sleep(3)  
device.touch(By.id("id/btn_disagree"),device.DOWN_AND_UP)  


注意点:
1.device需要用easymonkeydevice再次封装
2.touch方法id的如何使用
EasyMonkeyDevice类里面还有很多方法,包括exists(By)、getText(By)、type(By,String)、visible(By)等等。

再来个长点的脚本:
from com.android.monkeyrunner import MonkeyRunner as MR  
from com.android.monkeyrunner import MonkeyDevice as MD  
from com.android.monkeyrunner import MonkeyImage as MI  
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By  
from com.android.chimpchat.hierarchyviewer import HierarchyViewer as HV  
from com.android.hierarchyviewerlib.device import ViewNode as VN  
  
T528d=MR.waitForConnection(10)  
if T528d:  
    print("Connect device successful!")  
else:  
    print("Connect device failed!")  
eT528d=EasyMonkeyDevice(T528d)  
hvT528d=T528d.getHierarchyViewer()  
T528d.installPackage("D:\\MonkeyRunnerDemo\\Apps\\estore.apk")  
T528d.startActivity(component="com.eshore.ezone/.StartActivity")  
MR.sleep(3)  
vnT528d=hvT528d.findViewById("id/btn_agree")  
print("Width: "+str(vnT528d.width))  
print("Height: "+str(vnT528d.height))  
vnT528dCoordinate1=hvT528d.getAbsoluteCenterOfView(vnT528d)  
print("vnT528dCoordinate1X: "+str(vnT528dCoordinate1.x))  
print("vnT528dCoordinate1Y: "+str(vnT528dCoordinate1.y))  
vnT528dCoordinate2=hvT528d.getAbsolutePositionOfView(vnT528d)  
print("vnT528dCoordinate2X: "+str(vnT528dCoordinate2.x))  
print("vnT528dCoordinate2Y: "+str(vnT528dCoordinate2.y)) 


        附上运行结果:
Width: 165
Height: 49
vnT528dCoordinate1X: 127
vnT528dCoordinate1Y: 680
vnT528dCoordinate2X: 45
vnT528dCoordinate2Y: 656

        ViewNode类里面还有很多属性,包括parent(获取父控件)、children(获取子控件)、left、top等等,这里就不一个个挨着讲了,自己看吧,呵呵。

另外一篇比较全,比较好的monkeyrunner文章
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:35:27
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/11808/
本文WWW.DOC100.NET DOC100.NET版权所有。