Is there a way to find if the XCUIElement has focus or not?

后端 未结 5 1491
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 01:53

One of my screen has multiple text fields, I can land to this screen from different other screens. In each case I am making one or another text field as first responder. I a

5条回答
  •  星月不相逢
    2020-12-31 02:06

    Based on @hris.to's excellent answer, I put together this little extension (works in Swift 4 as well)...

    extension XCUIElement
    {
        func hasFocus() -> Bool {
            let hasKeyboardFocus = (self.value(forKey: "hasKeyboardFocus") as? Bool) ?? false
            return hasKeyboardFocus
        }
    }
    

提交回复
热议问题