python 设置输入法为英文,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()
總結
以上是生活随笔為你收集整理的python 设置输入法为英文,appium+python环境下的输入法切换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何实现win7远程桌面连接?
- 下一篇: python操作hbase,Python