python3+appium,怎么输入中文,并且调用搜狗或调出手机键盘;

我现在做的这个项目,搜索框输入内容后,需要使用输入法的ENTER键,app没有搜索按钮;

1.第一步先将drvier中加入

'unicodeKeyboard': "True", 
 # 使用unicode输入法,

可以使用appium输入中文:

keywords.send_keys('泗阳')

第二步,重新调起手机安装的搜索输入法:

adb shell ime list -s

使用以上语句看一下自己手机的输入法名,我的机器使用的是第三个搜狗的,替换一下语句:

adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME

第三步:

新建一个文件,将第二步包装成一个包

#coding=utf-8
import sys
import imp
imp.reload(sys)
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'
command4 ='adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME'

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

class InputMethod:


   # def enableLatinIME(self):
   #  os.system(command2)

   #切换appium输入法为当前输入法
   def enableAppiumUnicodeIME(self):
      command4 = 'adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME'
      os.system(command4)

第四步:调用这个包

from Resources.basic.inputMethod import InputMethod

#from Resources.basic.是文件路径

第五步:使用语句

# 切换appium输入法为搜狗输入法:
InputMethod.enableAppiumUnicodeIME(driver)

#完整使用

keywords.send_keys('泗阳')
time.sleep(2)
myprint('6666')
#切换appium输入法为搜狗输入法:
InputMethod.enableAppiumUnicodeIME(driver)
time.sleep(5)
# KEYCODE_ENTER 回车键 66
driver.keyevent(66)
time.sleep(2)
driver.keyevent(66)
time.sleep(2)

猜你喜欢

转载自blog.csdn.net/linmumum/article/details/89515458