Hide keyboard on IOS while testing web application


My use case is to hide keyboard after entering text in a web application.
I have tried various ways as mentioned below but was not successful.

We use same code for android and IOS, so we use AppiumDriver

  • Switch to “Native_App” and do appiumDriver.hideKeyboard(): Clicks on return but it doesnt hide keyboard
  • Cast Appium Driver to IOSDriver and try to hide
    IOSDriver< MobileElement> d = (IOSDriver) appiumDriver;
    d.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, “Done”);
    Am getting a cast exception,
    java.lang.ClassCastException: io.appium.java_client.AppiumDriver cannot be cast to io.appium.java_client.ios.IOSDriver
    and unable to proceed further.
  • Tried clicking on other elements on the page. But its flaky and the test results are not stable.

Is there any other way to do it.