我现在做的这个项目,搜索框输入内容后,需要使用输入法的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