0

我正在尝试编写一个python脚本并通过monkeyrunner运行它。该脚本应在特定时间自动点击 android 应用程序中的按钮。

通过 CMD 运行此脚本时(我使用的是 Windows):

在 CMD 中运行:

monkeyrunner C:\test\autoclick.py

Python脚本:

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

device= MonkeyDevice
for i in range(5):
    device = MonkeyRunner.waitForConnection(8)
    if device != None:
        print "Device found..."
        break;

device.press("KEYCODE_NOTIFICATION", "DOWN_AND_UP")
time.sleep(1)
device.press("KEYCODE_BACK", "DOWN_AND_UP")

我收到以下错误:

131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
pt terminated due to an exception
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Synta
xError: ("mismatched input '\\n' expecting COLON", ('C:\\test\\autoclick.py', 10
, 17, 'for i in range(5)\n'))

131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.fixParseError(ParserFacade.java:92)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.parse(ParserFacade.java:184)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.compile_flags(Py.java:1731)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:514)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)

131001 20:18:45.634:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:18
9)

我正在使用通过 Eclipse 更新管理器安装的 Jython 2.5.3 和 PyDev 在 Eclipse 中编写脚本。我的 Python 版本是 3.3.2。任何帮助,将不胜感激!

注意:我试图使用本教程测试我的设置,但它看起来有点过时了。

4

0 回答 0