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

后端 未结 5 1372
佛祖请我去吃肉
佛祖请我去吃肉 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:07

    I have observed some instances where

    XCUIApplication().textFields[{index/identifier}].selected
    

    does not return true even when I had my cursor focussed on the text field but I was able to enter text with .typeText(). However, .enabled correctly returns true , It appears 'enabled' value represents that UI element has accessibility enabled and you can interact with it.

    Not a clean solution but you can try,

    XCUIApplication().textFields.elementMatchingPredicate("predicate")
    

    or .elementMatchingType() to get XCUIElement and write your test block while handling the exception condition with guard statement to throw appropriate error if the textField is not found.

提交回复
热议问题