Soft keyboard not present, cannot hide keyboard - Appium android

前端 未结 2 352
长情又很酷
长情又很酷 2021-01-12 03:42

I am getting following exception:

 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original          


        
2条回答
  •  清酒与你
    2021-01-12 04:22

    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.

提交回复
热议问题