Testing if an element is visible with Xcode 7 UITest

后端 未结 6 1384
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 10:19

I want to verify if an element is visible or not depending on its .hidden property but I don\'t find a valid way to do that using the new Xcode 7 UI test stuff.

6条回答
  •  执念已碎
    2020-12-03 10:33

    I agree hittable doesn't always work for buttons (Swift 2.0, XCode 7.2)

    I just discovered that if button is visible, you can find it ONLY among buttons, while if button is hidden, you can find it's tag in staticTexts as well!

    XCTAssertFalse(app.buttons["Log out"].exists && app.staticTexts["Log out"].exists) // This button is visible (hidden = false)
    XCTAssert(app.buttons["Log in"].exists && app.staticTexts["Log in"].exists) // This one is hidden
    

    Hacky, but works for buttons. Apple should just introduce .hidden or .visible along .hittable and .exists

提交回复
热议问题