Ios driver.hidekeyboard(); doesn't operate

hey
i’m trying to close the keyboard with :
driver.hidekeyboard();
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:

driver.hidekeyboard('Enter')

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:
/private/var/folders/5h/7jlv99px0kj29yz4wltblxp00000gp/T/testng-eclipse-146364900/testng-customsuite.xml

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: ‘10.0.0.4’, os.name: ‘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(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at io.appium.java_client.ios.IOSDriver.hideKeyboard(IOSDriver.java:141)
at com.myearlysense.myearlysense_TESTCASES.Signup_Feature.Enter_To_Signup_Screen(Signup_Feature.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)

===============================================
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
TestMethodWorker.run() line: 108
TestRunner.privateRun(XmlTest) line: 774
TestRunner.run() line: 624
SuiteRunner.runTest(TestRunner) line: 359
SuiteRunner.runSequentially() line: 354
SuiteRunner.privateRun() line: 312
SuiteRunner.run() line: 261
SuiteRunnerWorker.runSuite(SuiteRunnerMap, XmlSuite) line: 52
SuiteRunnerWorker.run() line: 86
RemoteTestNG(TestNG).runSuitesSequentially(XmlSuite, SuiteRunnerMap, int, String) line: 1215
RemoteTestNG(TestNG).runSuitesLocally() line: 1140
RemoteTestNG(TestNG).run() line: 1048
RemoteTestNG.run() 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 = Appium::TouchAction.new.tap x: 100, y: 100
        action.perform
      else
        log.info 'Dismissing keyboard'
        apm.driver.hide_keyboard done_key
        1.upto(5) do
          page_class = nil
          wait = AppiumCommon::Wait.new(:timeout => settings.timeout_short)
          wait.until { page_class = apm.appium_module.get_page_class }
          if (!page_class.include?('UIAKeyboard'))
            log.info 'Keyboard dismissed'
            break
          else
            log.info 'Keyboard still visible, waiting...'
            sleep settings.timeout_tiny
          end
        end
      end
    end
  end

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

Hi,
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

hey
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”);