This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 18
Jan 2016

After scratching my head for many hours, I have finally figured out how to hide the keyboard. So I thought I would share info.

Background

There are two documented methods to hide the keyboard:

driver.hideKeyboard()

driver.hideKeyboard(String)

Both these methods (as of date) have open bugs on Appium's Github page. In general, they do not appear to work reliably for iOS.

So how to hide the keyboard? (a workaround)

  1. First, manually create the situation where your keyboard will be raised. (For example, enter text in a UIATextField.)
  2. Now observe the raised keyboard on your iPhone. What is the bottom-right key saying?
  3. In my example screenshot, the key is called return.
  4. Next, verify that manually pressing this key hides the keyboard.

If yes, you can go ahead and use:

driver.sendKeys(Keys.RETURN)

Notes

  1. Verified on Appium 1.4.13, OSX 10.11, iOS 9.1, Appium Java Client 3.3.0.
  • created

    Jan '16
  • last reply

    May '18
  • 17

    replies

  • 10.9k

    views

  • 13

    users

  • 3

    likes

  • 5

    links

1 month later
3 months later

below is the method to hide the keyboard on iOS

IOSDriver< WebElement> AD= (IOSDriver) driver;
AD.getKeyboard().sendKeys(Keys.RETURN);

its working fine for me

you can use following code:
EventFiringWebDriver sExecutor = new EventFiringWebDriver(Driver);
sExecutor.ececuteScript("UIATarget.localTraget.frontMostApp.keyboard.buttons()[\"Hide Keyboard\".tap();");

Same worked for me. this is for java.

13 days later

Hi All,

In some conditions there are buttons like Done . How to click on that using this same option.

IOSDriver< WebElement> AD= (IOSDriver) driver;
AD.getKeyboard().sendKeys(Keys.RETURN); //THIS WORK FINE

AD.getKeyboard().sendKeys(Keys.DONE); //THIS DOESN'T WORK

3 months later
3 months later

Thanks @nitinmania I can confirm that your solution works with iOS 10.2 simulator as well.

But I'm not sure even when "Done" button is visible on keyboard, why Keys.DONE is not valid

Regards,
Vikram

When i am using above command with IOSDriver + Native App and it is showing this error message
org.openqa.selenium.WebDriverException: Execute script is not supported.

@FindBy(xpath = "//*[@name='Hide keyboard']")
WebElement btn_hideKeyboard;

Perform operation on this Webelement.

Is it applicable for C# ? Is it available for Java too ?? @FindBy(how= HOW.NAME, using = "Hide keyboard")

What is how=HOW.NAME?Can we use it for all the tags , basically when are we
suppose to use this ?

1 month later
1 year later

Hi,
For me clicking on ‘return’ [softkey on iOS real device] doesn’t hides the keyboard.
Could you please suggest some other scenarios?

@Chhavi_Singh
In my experience, sending Keys.RETURN works great until you hit a multi-line text box where a return keeps the user in the input (I am testing a hybrid app). I found that in this case I had to put in a dummy touch action to an unused part of the top of the screen which brings the keyboard down…
new TouchAction((MobileDriver) appDriver).tap(260,10).perform();