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.
otherElements
? Can you try withsearchBars
? – CrawlstaticTexts()
orelementBoundByIndex()
? Is this simulating iPad or iPhone? – Morphosis