我有一个包含嵌套页面的应用程序。我为 monkeyrunner 写了一个脚本。我的脚本能够启动应用程序并访问页面的对象。现在,当我触摸我的一个按钮时,它会加载下一页。现在我无法对第二页的对象(button2)执行触摸事件。
#! /usr/bin/env monkeyrunner
import sys
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.android.monkeyrunner.easy import EasyMonkeyDevice
from com.android.monkeyrunner.easy import By
# connect to the device
device = MonkeyRunner.waitForConnection()
apk_path = device.shell('pm path com.test.myApp')
if apk_path.startswith('package:'):
print "myapp already installed."
else:
print "myapp not installed, installing APKs..."
device.installPackage('myApp.apk')
print "launching myapp..."
device.startActivity(component='com.test.myApp/com.test.myApp.main')
# use the EasyMonkey API
easyDevice = EasyMonkeyDevice(device)
MonkeyRunner.sleep(5)
easyDevice.touch(By.id('id/button1'),MonkeyDevice.DOWN_AND_UP)
#on click button 1 user enters in page2
#press button2 of page 2
easyDevice.touch(By.id('id/button2'),MonkeyDevice.DOWN_AND_UP)
print "end"
button1 点击(触摸)事件正确完成。但无法在第 2 页执行 button2 点击(触摸)事件。为什么?