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.
Neither element nor any descendant has keyboard focus when running XCTestCase in a real iPhone
I decided to answer myself rather than closing the question. I'll tell what went wrong in my code. The main mistake I have done was continueAfterFailure set as true. Because of that, the error shown in the wrong line not the actual error throwing line.
So the solution is,
continueAfterFailure = false
and
usernameTextField.tap()
sleep(2)
usernameTextField.typeText("TEST")
There should be a small waiting time till keyboard appears in the web view before type text.
how to Detect if Keyboard is shown in Xcode UI test
Add two observers
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardVisible:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardHidden:", name: UIKeyboardDidHideNotification, object: nil)
func keyboardVisible(notif: NSNotification) {
print("keyboardVisible")
}
func keyboardHidden(notif: NSNotification) {
print("keyboardHidden")
}
Whenever the keyboard is visible keyboardVisible
will be called and whenever the keyboard is hidden keyboardHidden
will be called.
Related Topics
How to Copy SQLite Database When Application Is Launched in iOS
How to Set Mime Type of Application/Vnd.Apple.Pkpass in Order to Share Pass by Link or Email
Xcode 4.2: How to Import .H File from Subproject
This Class Is Not Key Value Coding-Compliant for the Key Xxxxxx
How to Get Core Data Object from Specific Object Id
Alamofire Download in Background Session
How to Manage Cookies with Uiwebview in Swift
Xcode 4: Creating a Uiview Xib, Not Properly Connecting
Found an Unexpected MACh-O Header Code: 1918975009 in Xcode 6
Firebase Chat Push Notifications
Replace Occurrences of Nsnull in Nested Nsdictionary
What Is Most Common and Correct Practice to Get a Cgfloat from an Nsnumber
How to Present View Controller from Right to Left in iOS Using Swift
How to Use the Uisearchbar and Uisearchdisplaycontroller