【问题标题】:Soft keyboard not present, cannot hide keyboard - Appium android软键盘不存在,无法隐藏键盘 - Appium android
【发布时间】:2016-05-04 00:24:17
【问题描述】:

我收到以下异常:

 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

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

【问题讨论】:

    标签: android testing selenium-webdriver keyboard appium


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      我也收到此错误,我在 setUp 方法中使用以下代码进行更正:

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

      您可以在这里查看答案: Keyboard in Android physical device isn’t always hidden while using Appium

      【讨论】:

      • 谢谢。之后我不需要在任何地方隐藏键盘?
      • 是的,在这种情况下,您必须转到手机中的设置,您会看到默认键盘设置为 appium,因此不再需要键盘。这是我尝试了很多的更好的解决方案。
      • 再次感谢!如果有效,我会检查并标记为答案
      猜你喜欢
      • 2011-02-17
      • 2022-12-14
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多