How to check the virtual keyboard active in Android using Appium Automation?

How to check the virtual keyboard active in Android using Appium Automation?

Thanks,
Sanoj

Run adb command - ‘adb shell dumpsys input_method | grep mInputShown
If you run on windows command prompt replace ‘grep’ with ‘FINDSTR’ . Output will be like this - “mShowRequested=false mShowExplicitlyRequested=false mShowForced=false mInputShown=false

check mInputShown flag if true means keyboard is shown , then hide keyboard by driver.pressKeyCode(AndroidKeyCode.BACK); appium API.

1 Like

@sanoj27, what problem are you trying to solve. Are you trying to close the keyboard if it’s open? If so, you can use the hide_keyboard method as described in How to know if android virtual keyboard is open

Thank you very much @auto-geek for the reply and its working for me. I have one more concern here,
have any method to determine the same for iOS devices?

Thanks,
Sanoj

@sanoj27 i have never worked on iOS. But did u try ((IOSDriver) wd).hideKeyboard(HideKeyboardStrategy.PRESS_KEY,"Hide keyboard"); this method of appium ?

I tried the same, still sometime keyboard is visible sometime not, so I mentioned driver.hidekeyboard() in a try catch() block, but sometime driver.hidekeyboard is unable to hide the visible keyboard. Please let me know how can I find out the keyboard element so that I can resolve the issue.
or
I want to try the below approach :
if keyboard element is found then will press device back button,

In my opinion above approach would be best to resolve hidekeyboard() issue.

See the comment above by autogeek posted Dec '15