Appium iOS Guide: hiding the keyboard on real devices


#1

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.

Dismiss ios keyboard after typing in 1.6 and ruby
#2

How do you use the sendKeys method on a driver object? I thought we can only do sendKeys on a WebElement object ?


Appium iOS Real Device Hide Keyboard
#3

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


#4

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.


#5

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


#6

Hi,

you can you ascii values for that i.e

driver.getKeyboard().pressKey("\n");


#7

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


#8

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.


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

Perform operation on this Webelement.


#10

Will it work for iPhone native apps?


#11
@FindBy(how= HOW.NAME, using = "Hide keyboard") WebElement btn_hideKeyboard; 

I think it will be better


#12

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


#13

For Java it works. I use it


#14

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


#15



#16

how do you do this in Ruby?


#17

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


#18

@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();