UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField xcode xcode

UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField


This issue caused me a world of pain, but I've managed to figure out a proper solution. In the Simulator, make sure I/O -> Keyboard -> Connect hardware keyboard is off.


Recently we found a hack to make solution from accepted answer persistent. To disable Simulator setting: I/O -> Keyboard -> Connect hardware keyboard from command line one should write:

defaults write com.apple.iphonesimulator ConnectHardwareKeyboard 0

It will not affect a simulator which is running - you need to restart simulator or start a new one to make that setting have its effect.


I have written a small extension (Swift) which works perfect for me.Here is the code:

extension XCTestCase {    func tapElementAndWaitForKeyboardToAppear(element: XCUIElement) {        let keyboard = XCUIApplication().keyboards.element        while (true) {            element.tap()            if keyboard.exists {                break;            }            NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 0.5))        }    }}

The main idea is to keep tapping an element (text field) before the keyboard is presented.