Ios driver.hidekeyboard(); doesn't operate

i’m trying to close the keyboard with :
and nothing happens

any ideas?

driver.hidekeyboard takes a string parameter that represents the key you would hit to dismiss the keyboard. So for example, if the key was ‘Enter’ it would look like:


Hey thanks for your comment
I tried your solution and I still get javascript exception

I wonder what the exception looks like? Also, what language are you using?

Java and Ill post the exception

[TestNG] Running:

FAILED: Enter_To_Signup_Screen
org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.19 seconds
Build info: version: ‘2.52.0’, revision: ‘4c2593c’, time: ‘2016-02-11 19:03:33’
System info: host: ‘earlysensesMBP2’, ip: ‘’, ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.5’, java.version: ‘1.7.0_79’
Session ID: 283a64ea-7949-43ee-85ff-26e1536f56cb
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{platform=MAC, databaseEnabled=false, javascriptEnabled=true, browserName=iOS, webStorageEnabled=false, networkConnectionEnabled=false, desired={}, locationContextEnabled=false, warnings={}, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.openqa.selenium.remote.ErrorHandler.createThrowable(
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(
at org.openqa.selenium.remote.RemoteWebDriver.execute(
at io.appium.java_client.DefaultGenericMobileDriver.execute(
at io.appium.java_client.AppiumDriver.execute(
at io.appium.java_client.ios.IOSDriver.execute(
at io.appium.java_client.ios.IOSDriver.hideKeyboard(
at com.myearlysense.myearlysense_TESTCASES.Signup_Feature.Enter_To_Signup_Screen(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.testng.internal.MethodInvocationHelper.invokeMethod(
at org.testng.internal.Invoker.invokeMethod(
at org.testng.internal.Invoker.invokeTestMethod(
at org.testng.internal.Invoker.invokeTestMethods(
at org.testng.internal.TestMethodWorker.invokeTestMethods(
at org.testng.TestRunner.privateRun(
at org.testng.SuiteRunner.runTest(
at org.testng.SuiteRunner.runSequentially(
at org.testng.SuiteRunner.privateRun(
at org.testng.SuiteRunnerWorker.runSuite(
at org.testng.TestNG.runSuitesSequentially(
at org.testng.TestNG.runSuitesLocally(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(

Default test
Tests run: 1, Failures: 1, Skips: 0

Default suite
Total tests run: 1, Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@d233caf: 9 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 8 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6155b814: 19 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@7d8bddf0: 63 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@4fee5bed: 10 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@2b29f6e7: 46 ms

What version of Appium is this? I’m reading that some older versions have a bug related to hidekeyboard().

Version 1.4.13 (Draco)

Can you set a breakpoint and debug? I’m curious as to where the Javascript is being called.

ill try do it I’m kind new so if you can guide me it will be great

Set the breakpoint at driver.hidekeyboard and step in. Debugging can be a bit of an art, so you may want to play around with it, stepping in or stepping over as the case may be. You should be able to step into the underlying Appium code and see what is being called. Java is pretty good for doing this.

do you have may be example for handling the keyboard on real device ?

from the break point
Signup_Feature [TestNG]
org.testng.remote.RemoteTestNG at localhost:60257
Thread [main] (Suspended (breakpoint at line 37 in Signup_Feature))
Signup_Feature.Enter_To_Signup_Screen() line: 37
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object…) line: 606
MethodInvocationHelper.invokeMethod(Method, Object, Object[]) line: 85
Invoker.invokeMethod(Object, ITestNGMethod, Object[], int, XmlSuite, Map<String,String>, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods, FailureContext) line: 639
Invoker.invokeTestMethod(Object, ITestNGMethod, Object[], int, XmlSuite, Map<String,String>, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods, FailureContext) line: 816
Invoker.invokeTestMethods(ITestNGMethod, XmlSuite, Map<String,String>, ConfigurationGroupMethods, Object, ITestContext) line: 1124
TestMethodWorker.invokeTestMethods(ITestNGMethod, Object, ITestContext) line: 125 line: 108
TestRunner.privateRun(XmlTest) line: 774 line: 624
SuiteRunner.runTest(TestRunner) line: 359
SuiteRunner.runSequentially() line: 354
SuiteRunner.privateRun() line: 312 line: 261
SuiteRunnerWorker.runSuite(SuiteRunnerMap, XmlSuite) line: 52 line: 86
RemoteTestNG(TestNG).runSuitesSequentially(XmlSuite, SuiteRunnerMap, int, String) line: 1215
RemoteTestNG(TestNG).runSuitesLocally() line: 1140
RemoteTestNG(TestNG).run() line: 1048 line: 112
RemoteTestNG.initAndRun(String[], CommandLineArgs, RemoteArgs) line: 205
RemoteTestNG.main(String[]) line: 176
Thread [ReaderThread] (Running)
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java (Mar 15, 2016, 10:19:05 PM)

My framework is in Ruby. We do some defensive programming, maybe you can translate to Java?

 def dismiss_keyboard (done_key, mode='none')
    if (iPhone?)
      if (mode == 'touch')
        action = x: 100, y: 100
      else 'Dismissing keyboard'
        apm.driver.hide_keyboard done_key
        1.upto(5) do
          page_class = nil
          wait = => settings.timeout_short)
          wait.until { page_class = apm.appium_module.get_page_class }
          if (!page_class.include?('UIAKeyboard'))
   'Keyboard dismissed'
   'Keyboard still visible, waiting...'
            sleep settings.timeout_tiny

ok so i cheat a little bit
i used the record option and check how to close the keyboard
my last resort

You can hide your onscreen keyboard by two ways with AppiumDriver
1.Using driver.hidekeyboard() if keyboard is visible on screen
2.Using driver.navigate().back();

If both of the above ways doesn’t work then I have one more workaround for this, please let me know if you fails to hide by above 2 ways, thanks

i tried the first option for driver.hidekeyboard()
and nothing happens
same for the 2nd option.

So workaround is try to click on any other element other than text field,your keyboard will be automatically closed
or one more way is try to use sendkeys(Keys.Esc) for any text field

Thanks I’ll try it, I used the record to see the method for tapping on the done button

driver.hideKeyboard(“PRESS_KEY”, “Done”);