1
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.buttons[@"Committee"] tap];
[app.buttons[@"Login"] tap];
[app.buttons[@"Add Presenter"] tap];

XCUIElement *nameTextField = app/*@START_MENU_TOKEN@*/.textFields[@"Name"]/*[[".scrollViews.textFields[@\"Name\"]",".textFields[@\"Name\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/;
[nameTextField tap];
[nameTextField typeText:@"A"];

XCUIElement *topicTextField = app/*@START_MENU_TOKEN@*/.textFields[@"Topic"]/*[[".scrollViews.textFields[@\"Topic\"]",".textFields[@\"Topic\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/;
[topicTextField tap];
[topicTextField tap];

my error is when run the UI test I receive UI Testing Failure

Neither element nor any descendant has keyboard focus.

Attributes: TextField however the test above passed I have attached a screenshot of what exactly failing enter image description here

Senseful
  • 86,719
  • 67
  • 308
  • 465
Walee
  • 13
  • 5
  • This might help: http://stackoverflow.com/questions/32184837/ui-testing-failure-neither-element-nor-any-descendant-has-keyboard-focus-on-se – ovejka Dec 23 '15 at 12:28

2 Answers2

2

I faced this same problem with Xcode 7.0.1 and was able to resolve it by turning off the connected hardware keyboard in the simulator settings. Hardware -> Keyboard -> Connect Hardware Keyboard (uncheck this). link

Community
  • 1
  • 1
Yogesh Khatri
  • 319
  • 3
  • 7
0

Works for me for native screens:

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)
    }
}
Sameer Technomark
  • 1,399
  • 1
  • 10
  • 12