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.
I found something:
let app = XCUIApplication()
app.tables.searchFields["Search"].tap()
app.searchFields["Search"].typeText("something")
It looks strange, but it works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With