This is my case:
let passwordSecureTextField = app.secureTextFields[\"password\"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText(\"wrong_pass
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.
Use a sleep between launching the app and typing in data in textfields like this:
sleep(2)
In my case I was keeping getting this error every time and only this solution helped my out.
No Need to turn on/off keyboard in I/O. Don't use .typeText for secureTextField, just use
app.keys["p"].tap()
app.keys["a"].tap()
app.keys["s"].tap()
app.keys["s"].tap()
Bonus: You get keyboard sound click :)
Works for me:
extension XCUIElement {
func typeTextAlt(_ text: String) {
// Solution for `Neither element nor any descendant has keyboard focus.`
if !(self.value(forKey: "hasKeyboardFocus") as? Bool ?? false) {
XCUIDevice.shared.press(XCUIDevice.Button.home)
XCUIApplication().activate()
}
self.typeText(text)
}
}
In my case this Hardware -> Keyboard -> Connect Hardware Keyboard
-> Disable didn't worked for me.
But when I followed
1) Hardware -> Keyboard -> Connect Hardware Keyboard
-> Enabled and run the app
2) Hardware -> Keyboard -> Connect Hardware Keyboard
-> Disable.
It worked for me
This maybe help: I just add a "tap" action before the error; that´s all :)
[app.textFields[@"theTitle"] tap];
[app.textFields[@"theTitle"] typeText:@"kk"];