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

9
我遇到了以下异常:
 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()来隐藏屏幕上打开的软输入键盘。
如何确保键盘在隐藏之前是已经打开状态?或者有其他解决方法吗?

2个回答

7
我也遇到了这个错误,我通过在setUp方法中使用以下代码来进行纠正:
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

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


该问题涉及到IT技术,建议您参考以上链接获取更多信息。

1
谢谢。这之后我不需要在任何地方隐藏键盘了吗? - AnswerDroid
在这种情况下,您需要进入手机的设置,您会看到默认键盘设置为appium,因此不再需要键盘。这是我尝试过的更好的解决方案。 - Emna Ayadi
1
再次感谢!我会检查它,如果有效的话,将其标记为答案。 - AnswerDroid

5
使用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(),因为其行为可能在所有设备上都不同。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接