Home » Android » testing – Soft keyboard not present, cannot hide keyboard – Appium android

testing – Soft keyboard not present, cannot hide keyboard – Appium android

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am getting following exception:

 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

I am using driver.hideKeyboard() to hide soft input keyboard that is open on the screen.
How to ensure that keyboard is open before hiding it? OR any other workaround?

How to&Answers:

Use adb command to check whether keyboard has popped up or not

adb shell dumpsys input_method | grep mInputShown 
Output : mShowRequested=true mShowExplicitlyRequested=false mShowForced=false mInputShown=true

if mInputShown=true then yes software keyboard has popped up. Then use driver.pressKeyCode(AndroidKeyCode.BACK);

One way to do using java is

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();

PS: Please do not use driver.navigate().back() as its behavior may not be same on all devices.

Answer:

I also get this error, i correct it by using the following code in the setUp method :

capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

You can check answers here :
Keyboard in Android physical device isn’t always hidden while using Appium