trick14 trick14 - 5 months ago 33
Swift Question

Check UITextField focused on XCUITest

Is there any way to check a specific UITextField is focused(isFirstResponder) in XCUITest?

I'm currently using the below extension. It works but I believe there are better way to find it.

@available(iOS 9.0, *)
extension XCUIElement {
func isTextFieldFirstResponder(application: XCUIApplication) -> Bool {
return debugDescription.containsString("Keyboard Focused")


Have you tried checking the XCUIElement's (presumably a textField, but it works with secureTextFields and textViews as well) accessibilityElementIsFocused() property? That's what I'm currently doing, and it does seem to work.