trick14 trick14 - 1 year ago 92
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")

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download