首页 > 解决方案 > 如何使用带有 Appium 和 Python 的 Android 键盘键入文本?

问题描述

介绍

我正在使用 Appium 在 Python 3.7 中开发一个脚本。它将在真正的 Android 智能手机上自动执行一些任务。我的脚本需要在文本字段中输入一些文本。我不想使用 send_keys 方法或 ActionChains。我更喜欢使用智能手机的键盘逐个字符地键入文本。

问题

我调查并阅读了各种文档:

按键代码

https://appium.readthedocs.io/en/latest/en/commands/device/keys/press-keycode/

这把我带到了 Keyevent

https://developer.android.com/reference/android/view/KeyEvent.html

这让我想到了 KeyCharacterMap

https://developer.android.com/reference/android/view/KeyCharacterMap.html

老实说,在我读完这一切之后,我很难理解这一切。

所以我做了一些实验,尝试不同的代码行来看看会发生什么:

driver.press_keycode(0)
driver.press_keycode(1)
driver.press_keycode(2)

ETC...

似乎什么都没有发生。

有没有人知道一个好的教程或文章可以解释我如何使用键盘而不是 send_keys 方法和 ActionChains 在 Android 智能手机应用程序的文本字段中键入文本?

你能帮我找到路吗?

标签: python-3.xseleniumselenium-webdriverappiumappium-android

解决方案


推荐阅读