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
from sys import path
import random
path.append(r'C:\Program Files\Appium\\resources\app\node_modules\appium\build\lib')

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

command0 ='adb shell ime list -s'
command1 ='adb shell com.android.inputmethod.latin/.LatinIME'
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.nuance.swype.emui/com.nuance.swype.input.HuaweiIME'
command5 ='adb uninstall hongze.app.jsbc'


#可调试
# _list = []
# command0 = 'adb shell ime list -s'
# f = os.popen(command0)
# t = f.read()
# # print(t)
# _list = t.splitlines()
# _list.remove('io.appium.settings/.UnicodeIME')
# print(_list)
# method = _list[random.randint(0, len(_list) - 1)]
# print(method)
# command4 = 'adb shell ime set' + ' ' + method
# print(command4)

class InputMethod:
   #切换appium输入法为当前输入法
   def enableAppiumUnicodeIME(self):
      _list = []
      command0 = 'adb shell ime list -s'
      f = os.popen(command0)
      t = f.read()
      # print(t)
      _list = t.splitlines()
      _list.remove('io.appium.settings/.UnicodeIME')
      # print(_list)
      method = _list[random.randint(0, len(_list) - 1)]
      # print(method)
      command4 = 'adb shell ime set' + ' ' + method
      # print(command4)
      os.system(command4)

   #删除已存在的包
   def uninstallhost(host):
      command4 ='adb uninstall' + ' ' + str(host)
      os.system(command4)

   # 启动appium
   def start_appium(host):
      start = "start /b node (r'C:\Program Files\Appium\\resources\app\node_modules\appium\build\lib\')" + 'main.js --address 127.0.0.1 --port 4723'
      os.system(start)
第四步:调用这个包

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)

————————————————
版权声明:本文为CSDN博主「linmumum」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/linmumum/article/details/89515458

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值