Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 UI Testing - can't type text into search bar

The following UI Test code will successfully tap the UISearchBar element. The software keyboard appears and the search bar looks like it has focus. (ie. it animates as if someone tapped it)

let searchBar = XCUIApplication().otherElements["accessibility_label"]
searchBar.tap()
searchBar.typeText("search text")

However, typeText fails with:

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

Note: Hardware->Keyboard->Connect Hardware Keyboard is toggled off. This solved the same issue for text fields but the search bar is still failing.

like image 944
Stephen Avatar asked Oct 28 '15 14:10

Stephen


1 Answers

I found something:

let app = XCUIApplication()
app.tables.searchFields["Search"].tap()
app.searchFields["Search"].typeText("something")

It looks strange, but it works for me.

like image 124
rudald Avatar answered Sep 21 '22 17:09

rudald