【问题标题】:Android: Emulator: Python: Tabbing between Fields in a FormAndroid:模拟器:Python:在表单中的字段之间切换
【发布时间】:2013-02-21 19:22:39
【问题描述】:

我正在编写的 Android 应用程序中自动输入 SQLite 数据。 该应用程序是用 Java 编写的。 功能性 ui 测试是使用 MonkeyRunner 在 python 中编写的,并针对在我的 Win7 笔记本电脑上运行的 Android 4.2 模拟器运行。

#Touch the new alliance button
device.touch(358, 78, 'DOWN_AND_UP')
MonkeyRunner.sleep(3)
# Type name of new alliance
device.type("Legion of Anarchy")
MonkeyRunner.sleep(3)
#Touch the allc leader edittext
device.touch(88, 348, 'DOWN_AND_UP')
# Type name of alliance leader
device.type("DeathAngel")

在表单中,第一个字段已经有了焦点,所以我只需输入条目。 下一个触摸命令点击以下字段,但这并不总是有效。从我的笔记本电脑键盘上,我可以 TAB 到下一个字段...我只需要知道如何在 python/MonkeyRunner 中执行此操作。

谢谢!

【问题讨论】:

    标签: android python keyboard emulation monkeyrunner


    【解决方案1】:

    如果你可以通过键盘 TAB,那么你应该也可以通过 Monkeyrunner 进行 TAB:

    device.press('KEYCODE_TAB', MonkeyDevice.DOWN_AND_UP)
    

    但是,使用AndroidViewClient 并执行以下操作可能要容易得多:

    vc = ViewClient(*ViewClient.connectToDeviceOrExit())
    newAlliance = vc.findViewByIdOrRaise('id/new_alliance')
    newAlliance.type('Legion of Anarchy')
    allianceLeader = vc.findViewByIdOrRaise('id/alliance_leader')
    allianceLeader.type('DeathAngel')
    

    而且您不必担心屏幕坐标和其他问题。查看examples,您会发现很多想法。

    【讨论】:

    • 谢谢!我记得在某处看到过 AndroidViewClient 这个词,但没有意识到它能够做到这一点!
    猜你喜欢
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2019-12-17
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多