monkeyrunner easy.By viewid

时间:2013-09-03 10:59:37

标签: android monkeyrunner

我有带有选项菜单的android活动,其id为R.id.createRepository。现在我想使用Monkey runner向它发送触摸事件。我需要获取视图ID并尝试下面的代码:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice  
from com.android.monkeyrunner.easy import EasyMonkeyDevice, By  

device = MonkeyRunner.waitForConnection()  
easy_device = EasyMonkeyDevice(device)  

# Start your android app

# touch the view by id

easy_device.touch(By.id('id/createRepository'), MonkeyDevice.DOWN_AND_UP) # in activity java code I can refer to it as R.id.createRepository and I have even tried passing it in 

但是moneyrunner无法找到该视图。我需要帮助来定义正确的视图ID。

此致

米滕

1 个答案:

答案 0 :(得分:2)

您可以使用uiautomatorviewer查找视图的ID。它是位于工具下的android-sdk文件夹中的工具。

只需在屏幕中打开您的应用,其中包含未知ID的视图。然后打开uiautomatorviewer并截取屏幕截图。您将找到包含所有视图详细信息的应用布局。