Neither element nor any descendant has keyboard focus

After recording a test, I have this test code that has been generated.


    func testAddCustomerToWaitingQueue() {
      
        let app = XCUIApplication()
        app.buttons["AddButton"].tap()
      
        let firstLastNameTextField = app.textFields["First & Last Name"]
        firstLastNameTextField.tap()
        firstLastNameTextField.typeText("Bill Smith")
        app.textFields["Client Description"].typeText("A rather severe looking chap")
      
        let tablesQuery = app.tables
        tablesQuery/@START_MENU_TOKEN@*/.staticTexts["Rep Name"]/[[".cells.staticTexts[\"Rep Name\"]",".staticTexts[\"Rep Name\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
        tablesQuery/@START_MENU_TOKEN@*/.staticTexts["Paul"]/[[".cells.staticTexts[\"Paul\"]",".staticTexts[\"Paul\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
        tablesQuery/@START_MENU_TOKEN@*/.staticTexts["Reason for Visit"]/[[".cells.staticTexts[\"Reason for Visit\"]",".staticTexts[\"Reason for Visit\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
        tablesQuery/@START_MENU_TOKEN@*/.staticTexts["Account - Opening"]/[[".cells.staticTexts[\"Account - Opening\"]",".staticTexts[\"Account - Opening\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
      
        let commentsTextField = app.textFields["Comments"]
        commentsTextField.typeText("")
        commentsTextField.typeText("Please see post haste")
        app.buttons["Create"].tap()
        app.buttons["Confirm"].tap()
      
    }


Yet, when I run the tests, line 09 always fails with:

UI Testing Failure - Neither element nor any descendant has keyboard focus. Element:


What have I done wrong here? I'm using Xcode 7 beta 3 (7A152u) and recorded the test from the simulator.

Replies

Don't you need a line to tap the Client Description text field before you send the typeText to it?

I added the tap, but error remained.

I am having the exact same issue in Xcode 7 beta 4. Everything worked really well in beta 1, and it has been going downhill ever since.

In the Xcode7 Beta4 I had some troubles with some simple cases like entering a username field, then going and typing into the password field right below it. Even setting a .tap() command on the field wasn't working exactly as planned prior to typing some text.


However, I was able to find a particular work around with my particular setup, and not sure if this will be the same for you.


If when the keyboard is up on the simulator and it types the user's information in the first text field is there a "Next" option on the keyboard?


You should be able to set a breakpoint and then do a p print(app.debugDescription) and check to see if on the keyboard there's a "Next" option.


It may be as simple as something like this:

firstLastNameTextField.typeText("Bill Smith")
app.buttons["Next"].tap()
app.textFields["Client Description"].typeText("A rather severe looking chap")

I'm also seeing this happen. The test is failing when there's a view with two text fields that are supposed to be filled out before going to the view after.


When I first get to the view, the keyboard is present upon loading-


    [self.nameTextField becomeFirstResponder];
    [super viewWillAppear:animated];


When the test gets to that view, the element subtree (po app) displays the exact same elements from the previous view.


When I type po app.keyboard, it shows that the keyboard is available.


po app.keyboards

t = 57.79s Use cached accessibility hierarchy for com.me.myapp

t = 57.81s Find: Descendants matching type Keyboard

Find: Target Application

Output: {

Application 0x7fc5d1481ca0: {{0.0, 0.0}, {375.0, 667.0}}, label: 'My App'

}

↪︎Find: Descendants matching type Keyboard

Output: {

Keyboard 0x7fc5d168ea40: traits: 8589934592, {{0.0, 666.3}, {375.0, 253.1}}

}


po app.buttons

t = 119.37s Use cached accessibility hierarchy for com.me.myapp

t = 119.38s Find: Descendants matching type Button

Find: Target Application

Output: {

Application 0x7fc5d1481ca0: {{0.0, 0.0}, {375.0, 667.0}}, label: 'My App'

}

↪︎Find: Descendants matching type Button

Output: {

Button 0x7fc5d1782740: traits: 8724152321, {{9.4, -60.8}, {24.6, 24.6}}, label: 'Back'

Button 0x7fc5d1573410: traits: 8589934593, {{-51.6, 0.7}, {51.6, 51.6}}, label: 'Close more suggestions'

Button 0x7fc5d148fb50: traits: 8388609, {{7.0, 0.7}, {147.7, 23.4}}, label: 'Back to Main Menu'

Button 0x7fc5d14921c0: traits: 8589934649, {{0.0, 805.8}, {49.2, 49.2}}, label: 'shift'

Button 0x7fc5d178e070: traits: 8589934641, {{46.9, 869.0}, {46.9, 49.2}}, label: 'Next keyboard', value: Emoji

Button 0x7fc5d178e7f0: traits: 25769805873, {{93.8, 869.0}, {37.5, 49.2}}, label: 'Dictate'

Button 0x7fc5d178f6b0: traits: 8589934641, {{281.2, 869.0}, {93.8, 49.2}}, identifier: 'Next', label: 'NEXT'

}


So the app seems to be stuck in the previous view, even though the keyboard is showing up.


Recording doesn't work; all it does is keep having the following appear- [app typeText:@"sample text"]; - which isn't useful, because there are multiple text fields.


One thing to note: the keyboard doesn't actually appear in the simulator when text is typed. This happens with any app with the iOS 9 simulator.


Should we wait for the next seed?