The keyboard in the physical Android device is not always hidden when using Appium

When I want to hide the keyboard (because if I don’t hide it when I press the button under the keyboard, instead of pressing the confirmation button, the number from the keyboard is pressed), sometimes it is hidden in order with the command driver.hidekeyboard(); and in other cases it hides automatically.

Other times it tells me

An unknown error occurred on the server side while processing the command. (Original error: no soft keyboard, cannot hide the keyboard)

+3
source share
4 answers

Use the adb command to check if the keyboard has popped up or not.

 adb shell dumpsys input_method | grep mInputShown 

Exit: mShowRequested=true mShowExplicitlyRequested=false mShowForced=false mInputShown=true

if mInputShown=true , then a soft keyboard will appear. Then use driver.pressKeyCode(AndroidKeyCode.BACK);

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

+4
source

Faced a similar problem trying to work with emulators and real-time devices. One had a keyboard, and the other did not. Thus, driver.hideKeyboard(); used for failure for the latter. Just make sure the keyboard appears in both cases and then is hidden.

 driver.getKeyboard(); driver.hideKeyboard(); 

This works great for me. Hope this helps.

+3
source

@Emna After entering both fields, if hidekeyboard does not work, try. driver.navigate().back(); or wrap it like

 public void clickDeviceBackButton(){ driver.navigate().back(); } 

and call clickDeviceBackButton() in your test file

+2
source

Try to find the Static Text / link element on the page and .click (). This rejects the keyboard.

+2
source

All Articles