This is my case:
let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText("wrong_password") //here is an error
UI Testing Failure - Neither element nor any descendant has keyboard focus. Element:
What is wrong? This is working nice for normal textFields
, but problem arise only with secureTextFields
. Any workarounds?
We encountered the same error when setting the
accessibilityIdentifier
value for a custom view (UIStackView
subclass) containingUIControl
subviews. In that case XCTest was unable to get the keyboard focus for the descendent elements.Our solution was simply to remove the
accessibilityIdentifier
from our parent view and set theaccessibilityIdentifier
for the subviews through dedicated properties.I have written a small extension (Swift) which works perfect for me. Here is the code:
The main idea is to keep tapping an element (text field) before the keyboard is presented.
It occurred with me for many times. You have to disable Keyboard Hardware and Same Layout as OSX in your Simulator
Hardware/Keyboard (disable all)
After that keyboard software won't dismiss and your tests can type text
Use a sleep between launching the app and typing in data in textfields like this:
In my case I was keeping getting this error every time and only this solution helped my out.
Don't messed up, There problem caught the reason is you are recorded your testing time your app will connection hardware keyboard while your automatic testing time simulator takes only software keyboard. so for how to fix this issues. Just use software keyboard on your recording time. you can see the magic.