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

后端 未结 24 1470
难免孤独
难免孤独 2020-12-12 10:41

This is my case:

let passwordSecureTextField = app.secureTextFields[\"password\"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText(\"wrong_pass         


        
相关标签:
24条回答
  • 2020-12-12 11:04

    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.

    0 讨论(0)
  • 2020-12-12 11:05

    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.

    0 讨论(0)
  • 2020-12-12 11:05

    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 :)

    0 讨论(0)
  • 2020-12-12 11:05

    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)
        }
    }
    
    0 讨论(0)
  • 2020-12-12 11:06

    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

    0 讨论(0)
  • 2020-12-12 11:06

    This maybe help: I just add a "tap" action before the error; that´s all :)

    [app.textFields[@"theTitle"] tap];
    [app.textFields[@"theTitle"] typeText:@"kk"];
    
    0 讨论(0)
提交回复
热议问题