Xcode 11 - XCUITest unable to typeText on UISearchBar

Our app has a UISearchBar as part of a UINavigationItem's titleView.


The element layout looks like this:


    Window (Main), 0x600001ab6060, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600001ab6140, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x600001ab5ea0, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x600001ab5f80, {{0.0, 0.0}, {414.0, 896.0}}
            Other, 0x600001ab5ce0, {{0.0, 0.0}, {414.0, 896.0}}
              Other, 0x600001ab5dc0, {{0.0, 0.0}, {414.0, 896.0}}
                Other, 0x600001ab5b20, {{0.0, 0.0}, {414.0, 896.0}}
                  NavigationBar, 0x600001ab5c00, {{0.0, 44.0}, {414.0, 56.0}}, identifier: 'Search'
                    SearchField, 0x600001ab5960, {{0.0, 44.0}, {414.0, 56.0}}, identifier: 'searchTextField'


The SearchField is accessible but sending `typeText` doesn't do anything. It prints this error on console.


    t =    82.89s             Failed: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: SearchField, identifier: 'searchTextField'


The keyboard is open before sending typeText so i've no idea what's going on here. I tried using the Record feature to see what Apple does. Taping the Search bar with Record button causes it to crash with error

Timestamped Event Matching Error: Failed to find matching element


The implementation looks like this

        navigationController?.navigationBar.isAccessibilityElement = false
        navigationItem.isAccessibilityElement = false
        searchBar.isAccessibilityElement = true

        searchBar.accessibilityIdentifier = "searchTextField"
        searchBar.accessibilityTraits = [.searchField]
        navigationItem.titleView = searchBar

Replies

I am facing the same error. Could anyone from Apple look into this?

Could anyone from Apple look into this?

Keep in mind that DevForums is an informal site for community self help. If you’re looking for formal support from Apple, you should open a DTS tech support incident.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"