Search code examples
iosxcodeswiftxcode-ui-testing

Xcode ui test: staticTexts start with


I want to check if an element on my ui which start with a prefix is present. How is it possible to implement it in Xcode 7 UI Tests?

app.tables["AAA"].staticTexts["Fax: 0049XXXXXXXX"].exists

I have three element into a tableview cell and only one (the third or last one) starts with the prefix Fax: 0049. How can i check the present of this element?

I tried with

app.tables["AAA"].cells.staticTexts.elementBoundByIndex(2).exists

But nothing, some ideas? Cheers


Solution

  • You can use a BEGINSWITH predicate to check if an element starts with a prefix.

    let app = XCUIApplication()
    let faxPredicate = NSPredicate(format: "label BEGINSWITH 'Fax: '")
    let faxLabel = app.staticTexts.element(matching: faxPredicate)
    XCTAssert(faxLabel.exists)
    

    Here's a working example for selecting elements with a different BEGINSWITH predicate, a picker with multiple wheels.