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

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

This is my case:

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


        
相关标签:
24条回答
  • 2020-12-12 10:54

    Another answer, but for us the problem was the view was too close to another view that a Gesture recognizer on it. We found we needed the view to be at least 20 pixels away (in our case below). Literally 15 didn't work and 20 or more did. This is strange I'll admit, but we had some UITextViews that were working and some that were not and all were under the same parent and identical other positioning (and variable names of course). The keyboard on or off or whatever made no difference. Accessibility showed the fields. We restarted our computers. We did clean builds. Fresh source checkouts.

    0 讨论(0)
  • 2020-12-12 10:56

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

    0 讨论(0)
  • 2020-12-12 10:56

    Recently we found a hack to make solution from accepted answer persistent. To disable Simulator setting: 'Hardware -> 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.

    0 讨论(0)
  • 2020-12-12 10:56
    func pasteTextFieldText(app:XCUIApplication, element:XCUIElement, value:String, clearText:Bool) {
        // Get the password into the pasteboard buffer
        UIPasteboard.generalPasteboard().string = value
    
        // Bring up the popup menu on the password field
        element.tap()
    
        if clearText {
            element.buttons["Clear text"].tap()
        }
    
        element.doubleTap()
    
        // Tap the Paste button to input the password
        app.menuItems["Paste"].tap()
    }
    
    0 讨论(0)
  • 2020-12-12 10:56

    Sometime text fields are not implemented as text fields, or they're wrapped into another UI element and not easily accessible. Here's a work around:

    //XCUIApplication().scrollViews.otherElements.staticTexts["Email"] the locator for the element
    RegistrationScreenStep1of2.emailTextField.tap()
    let keys = app.keys
     keys["p"].tap() //type the keys that you need
     
     //If you stored your data somewhere and need to access that string //you can cats your string to an array and then pass the index //number to key[]
     
     let newUserEmail = Array(newPatient.email())
     let password = Array(newPatient.password)
     
     //When you cast your string to an array the elements of the array //are Character so you would need to cast them into string otherwise //Xcode will compain. 
     
     let keys = app.keys
         keys[String(newUserEmail[0])].tap()
         keys[String(newUserEmail[1])].tap()
         keys[String(newUserEmail[2])].tap()
         keys[String(newUserEmail[3])].tap()
         keys[String(newUserEmail[4])].tap()
         keys[String(newUserEmail[5])].tap()       

    0 讨论(0)
  • 2020-12-12 10:56

    Had the same issue with Securetextfields. The connect hardware option in my Simulator was of, but still ran into the issue. Finally, this worked for me (Swift 3):

     let enterPasswordSecureTextField = app.secureTextFields["Enter Password"]
        enterPasswordSecureTextField.tap()
        enterPasswordSecureTextField.typeText("12345678")
    
    0 讨论(0)
提交回复
热议问题