问题
When I want to hide the keyboard, (because if I don't hide it when I click into a button under keyboard a number from keyboard is pressed instead of the confirm button for example) some times it's hidden ok by the command driver.hidekeyboard(); and other times it's hidden automatically.
Other times it tells me
An unknown server-side error occurred while processing the command. (Original error: Soft keyboard not present, cannot hide keyboard)
回答1:
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);
PS: Please do not use driver.navigate().back() as its behavior may not be same on all devices.
回答2:
Faced a similar problem trying to work on emulator and real time devices. One had the keyboard displayed and another didn't. So the driver.hideKeyboard(); used to fail for the latter. Just made sure that the keyboard would appear in both the cases and then hidden.
driver.getKeyboard();
driver.hideKeyboard();
This works fine for me. Hope it helps.
回答3:
@Emna After inputting both field if hidekeyboard doesnt works try. driver.navigate().back(); or wrap it as
public void clickDeviceBackButton(){
driver.navigate().back();
}
and call clickDeviceBackButton() in your testcase
回答4:
Try to find a Static Text/link element on the page and .click() there. That dismisses the keyboard .
来源:https://stackoverflow.com/questions/34942654/keyboard-in-android-physical-device-isn-t-always-hidden-while-using-appium