Xcode ui test: staticTexts start with
Asked Answered
P

1

12

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

Piero answered 19/2, 2016 at 15:42 Comment(0)
B
28

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.

Bossism answered 19/2, 2016 at 17:3 Comment(2)
I was confused by the difference between staticTexts.matching(predicate) and staticTexts.element(matching: predicate). Quite subtle!Goldstone
Whoever stumbles on this like I did, you can also use ENDSWITH to check the end of labels.Screenplay

© 2022 - 2024 — McMap. All rights reserved.