Search code examples
iosxcuitest

UITest iOS waitForExistence returns false but element is visible


I am a litte new in iOS UITest so apologises if something does not make sense.

I am trying to assert if a staticText is visible but it always returns false despite being shown.

The Screen looks like this:

enter image description here

The test function code looks like this:

func verifyBlockedAccountsEmptyState() {
    print(profileListScreen.app.navigationBars["Blocked Accounts"].waitForExistence(timeout: 5))
    print(profileListScreen.app.staticTexts.element.label)
    print(profileListScreen.app.staticTexts["No blocked accounts"].waitForExistence(timeout: 5))

    var elementLabels = [String]()
    for i in 0..<profileListScreen.app.staticTexts.count {
        elementLabels.append (profileListScreen.app.staticTexts.element(boundBy: i).label)
    }
    print("staticTexts -> ", elementLabels)
}

And the output:

true
12:25 PM
false
staticTexts ->  ["12:25 PM"]

Any idea?

Thank you

EDIT If I try to record the XCUIElement I get the following error:

Timestamped Event Matching Error: Failed to find matching element

Solution

  • A problem may be caused by using the wrong element type.

    You probably should add a breakpoint and inspect this screen with lldb.

    Type po print(app.debugDescription) to print the whole hierarchy of elements and their actual types.