How to get the height of Keyboard in Android and iOS


There is a button at the bottom my a page. When keyboard is open there are chances that the button will be present behind the Keyboard. What is the best way I can detect it ? I had a thought that, by knowing the y co-ordinate of keyboard and the element we can figure this out.
But I do not know how to find the position of height of the keyboard. Kindly help at the earliest.

By default the keyboard element is not visible in the page source. You could try to enable the enableMultiWindows setting in order to “see” it (requires the most recent server version)

Hi @mykola-mokhnach can you give me a small code snippet, how to achieve it ? Should I need to set this property (enableMultiWindows) during appium driver creation ?

@coolvasanth if you don’t need keyboard anymore you can hide keyboard by using driver.hideKeyboard() method and perform desired action on specific button. From your description it’s not clear that what you want to achieve, do you need to click on this button when keyboard is opened or you just need to located the button only.
Exact manual steps are very important for automating any test case.

@abhiqa, Thanks for the reply. The test case requirement is to just ensure the button is not behind the keyboard. Below is the detailed steps for your reference.

  • Open search page and enter key ‘xyz’

  • When the keyboard is open the fab submit button which is present on the bottom right of the page should be visible(should be present above the keyboard).

  • After successful entering of the key the keyboard should suspend and the submit fab button should be present on the default state. (at the bottom left)

@coolvasanth you can use assertion to check whether the button is displayed or not on screen while keyboard is opened.
to do so you may use elements.isEmpty(); or element.isDisplayed(); after step 1
though i am not sure about the reliability of isDisplayed() method.

Alternatively if the button text is unique you can getText of particular button and store it in an element and matches after step 1 that it is displayed on the screen or not.

Hope it’ll solve your problem.

@abhiqa, thanks for the reply. I’m kind a aware of this approach, thanks for suggesting again, I have not tried it. Will test it and post the result here.