Keyboard is not present error occasionally happens and cause tests to crash

Python automatic scripts for iOS fail once in around 4-5 launches because of the following error:

[2019-12-20 03:27:22,210 Sensely] ERROR : Cannot clear ‘Answer field’ (‘type == “XCUIElementTypeTextView” AND name == “inputField”’): Verify available actions for element
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Error Domain=com.facebook.WebDriverAgent Code=1 “Keyboard is not present” UserInfo={NSLocalizedDescription=Keyboard is not present}

Using NOT real device, but simulator:
platformName: “iOS”
platformVersion: “13.3”
automationName: “XCUITest”
deviceName: “iPhone 11 Pro”

Any ideas why it happens? Tried setting hardware keyboard to False (as it was advised in other threads on different forums) but it doesn’t help (tests start crashing)

I wonder if the keyboard is just slow to render? You could try using an explicit wait to test for the keyboard’s presence.

Python syntax:

Appium specific (code is Java):