软键盘不存在,无法隐藏键盘 - Appium android

Ans*_*oid 8 testing keyboard android selenium-webdriver appium

我得到以下异常:

 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original error: Soft keyboard not present, cannot hide keyboard) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 368 milliseconds
Run Code Online (Sandbox Code Playgroud)

我正在使用driver.hideKeyboard()来隐藏屏幕上打开的软输入键盘.
在隐藏键盘之前如何确保键盘处于打开状态?或任何其他解决方法?

Emn*_*mna 7

我也得到这个错误,我通过在setUp方法中使用以下代码来纠正它:

capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看答案: 使用Appium时,Android物理设备中的键盘并不总是被隐藏


She*_*ami 5

使用adb命令检查键盘是否弹出

adb shell dumpsys input_method | grep mInputShown 
Output : mShowRequested=true mShowExplicitlyRequested=false mShowForced=false mInputShown=true
Run Code Online (Sandbox Code Playgroud)

如果mInputShown=true那时是软键盘弹出.然后用driver.pressKeyCode(AndroidKeyCode.BACK);

使用java的一种方法是

Process p = Runtime.getRuntime().exec("adb shell dumpsys input_method | grep mInputShown");
        BufferedReader   in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String outputText = "";

           while ((outputText = in.readLine()) != null) {

               if(!outputText.trim().equals("")){
                        String keyboardProperties[]=outputText.split(" ");
                        String keyValue[]=keyboardProperties[keyboardProperties.length-1].split("=");

                        String softkeyboardpresenseValue=keyValue[keyValue.length-1];
                        if(softkeyboardpresenseValue.equalsIgnoreCase("false")){
                                isKeyboardPresent=false;
                        }else{
                                isKeyboardPresent=true;
                        }
               }
           }
           in.close();
Run Code Online (Sandbox Code Playgroud)

PS:请不要使用,driver.navigate().back()因为它的行为可能在所有设备上都不一样.