使用monkeyrunner和python脚本的语法错误

时间:2013-10-02 03:02:00

标签: android python pydev jython monkeyrunner

我正在尝试编写一个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)

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

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

0 个答案:

没有答案