appium+python环境下的输入法切换

今天做appium+python的app UI自动化时,遇到app前端界面输入时自动加了空格,用send_keys()方法怎么都输入不了正确的手机号和银行卡号,不是输入错了,就是输入少了,经过自己的研究,总结出了下面的方法,记录一下,以备后用。

我自己写了一个python的切换输入法的方法类,在做appium+python的app UI自动化时,直接调用就可以了,现在分享出来:

文件名:inputMethod.py

#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

import os

command0 ='adb shell ime list -s'
command1 ='adb shell settings get secure default_input_method'
command2 ='adb shell ime set com.android.inputmethod.latin/.LatinIME'
command3 ='adb shell ime set io.appium.android.ime/.UnicodeIME'

#列出系统现在所安装的所有输入法
#os.system(command0)
#打印系统当前默认的输入法
#os.system(command1)
#切换latin输入法为当前输入法
#os.system(command2)
#切换appium输入法为当前输入法
#os.system(command3)

class InputMethod:

 #切换latin输入法为当前输入法
def enableLatinIME(self):
    os.system(command2)        

 #切换appium输入法为当前输入法
def enableAppiumUnicodeIME(self):
    os.system(command3)

需要调用时,方法如下:(注意要先引包)

#切换latin输入法为当前输入:
inputMethod.InputMethod().enableLatinIME()

#切换appium输入法为当前输入法:
 inputMethod.InputMethod().enableAppiumUnicodeIME()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,274评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,095评论 19 139
  • 前言:本篇文章并非我的原创,而是翻译自英文原著。这里的每一句话我都仔细揣摩过并且加以实践,着实花了一些时间,在此记...
    顾顾314阅读 22,264评论 0 19
  • 前言 做Android端功能自动化已有2年多的时间了,使用过的功能自动化框架有Robotium、Uiautomat...
    海波笔记阅读 17,167评论 3 66
  • 一、面向对象设计七大原则 单一职责原则(Single Responsibility Principle)每一个类应...
    戰敭阅读 2,750评论 0 0

友情链接更多精彩内容