appium: iOS fails to hide_keyboard on appium-xcuitest-driver 3.35.1

The problem

Believe it is related to this PR: https://github.com/appium/WebDriverAgent/pull/453

It was working on appium-xcuitest-driver 3.34.0 but fails on 3.35.1

driver.hide_keyboard fails to hide keyboard with error:

Selenium::WebDriver::Error::ElementNotInteractableError: Error Domain=com.facebook.WebDriverAgent Code=1 "Did not know how to dismiss the keyboard. Try to dismiss it in the way supported by your application under test." UserInfo={NSLocalizedDescription=Did not know how to dismiss the keyboard. Try to dismiss it in the way supported by your application under test.}
from InvalidElementStateError: Error Domain=com.facebook.WebDriverAgent Code=1 "Did not know how to dismiss the keyboard. Try to dismiss it in the way supported by your application under test." UserInfo={NSLocalizedDescription=Did not know how to dismiss the keyboard. Try to dismiss it in the way supported by your application under test.}

Environment

  • Appium version (or git revision) that exhibits the issue: 1.20.2
  • Last Appium version that did not exhibit the issue (if applicable): 1.20.1
  • Desktop OS/version used to run Appium: Mac Big Sur
  • Node.js version (unless using Appium.app|exe): v15.3.0
  • Npm or Yarn package manager: Yarn
  • Mobile platform/version under test: iOS 14.1
  • Real device or emulator/simulator: Simulator
  • Appium CLI or Appium.app|exe: CLI

Link to Appium logs

Code To Reproduce Issue [ Good To Have ]

driver.hide_keyboard

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@mykola-mokhnach So whats the workaround here, is it planned to be fixed? I upgraded to latest appium and its failing my tests.

“\n” worked for textfield if thats not in the login screen.

@mykola-mokhnach So whats the workaround here, is it planned to be fixed? I upgraded to latest appium and its failing my tests.

My workaround is to send ‘\n’ at the end of the value I’m sending. No issues so far.

Im doing this to hide the keyboard on IOS

List<MobileElement> allTxt = MobileDriverManagerIOS.getDriver().findElementsByXPath("//XCUIElementTypeStaticText");
MobileElement element      = allTxt.get(allTxt.size()-1);
MobileActionsIOS.click(element);

This will get list of all TextViews and then click the last element to avoid any scroll issues.

the hideKeyboard command is a best guess heuristic. the problem is there is no apple-provided way of reliably hiding the keyboard. that is why the other issues are closed. there’s nothing to do about it.

the appropriate solution is for you to do what a user would do. if it’s hard for a user to hide the keyboard, then it will be hard for you to do in the test as well. like if it takes special human knowledge to hide the keyboard, something like “tap outside the keyboard but make sure it’s not on any other element”, then, yeah, that’s a burden you’re putting on the user as well as yourself as a tester.

it might help to complain to apple about the lack of an api for hiding the keyboard via xcuitest.

Yes, these keyboard screens do not have a Done or Finished - the default used to be to click outside of the keyboard to clear - now its failing, so there is no way to hide a keyboard without a closing button?

Yes, there is no way to do that on iOS via APIs that Apple provides. Clicking outside of the keyboard is not safe if it is done on the server side, since it would select random coordinates for that. So there is no guarantee the click would be performed on a “safe” area. That is why it makes more sense if the client itself performs that action, because there it’s known at which position the click should happen.