目录

appium-键盘搜索

appium 键盘搜索

利用adb命令先切换为自己的输入法,按了搜索再切换为appium的输入法

查看当前手机的输入法

cmd执行下面的的代码

adb shell ime list -s

可以看到类似下面的结果,

C:\Users\LITP>adb shell ime list -s
com.baidu.input_mi/.ImeService
com.sohu.inputmethod.sogou.xiaomi/.SogouIME
io.appium.android.ime/.UnicodeIME

C:\Users\LITP>
执行adb命令

先写好一个执行cmd的方法

    /**
     * 执行adb命令
     * @param s 要执行的命令
     */
    private void excuteAdbShell(String s) {
        Runtime runtime=Runtime.getRuntime();
        try{
            runtime.exec(s);
        }catch(Exception e){
            print("执行命令:"+s+"出错");
        }
    }

在需要搜索的时候执行下面的代码,切换的输入法用自己查看列表的输入法内容,我这里是搜狗输入法

        //使用adb shell 切换输入法-更改为搜狗拼音,这个看你本来用的什么输入法
        excuteAdbShell("adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME");
        Thread.sleep(1000);
        //再次点击输入框,调取键盘,软键盘被成功调出
        clickView(page.getSearch());
        //点击右下角的搜索,即ENTER键
        pressKeyCode(AndroidKeyCode.ENTER);
        //再次切回 输入法键盘为Appium unicodeKeyboard
        excuteAdbShell("adb shell ime set io.appium.android.ime/.UnicodeIME");

有些手机pressKeyCode(AndroidKeyCode.ENTER);方法也不管用可以用String cmdstr="adb shell input keyevent 66";
Runtime.getRuntime().exec(cmdstr).waitFor();
替代pressKeyCode方法之前还是要切换成自己的输入法

python 搜索的实现,不需要切换输入法,直接使用就可以实现搜索

self.driver.keyevent(66)
self.driver.press_keycode(66)