Reputation: 1361
I have a text on my screen that is presented like:
@"New element #13"
How can I make universal test for it and reach this element by mask?
[[[XCUIApplication alloc] init].buttons[@"New element #**"] tap];
Upvotes: 1
Views: 83
Reputation: 17018
Sounds like you are trying to match text via a regular expression.
XCUIApplication *app = [[XCUIApplication alloc] init];
NSString *format = "label BEGINSWITH 'New element #'";
NSPredicate *predicate = [[NSPredicate alloc] initWithFormat:format];
XCUIElement *element = [app.buttons elementMatchingPredicate:predicate];
[element tap];
Note that if there are more than one button that matches the predicate Xcode might raise an exception.
You can find a Swift example (and working app) in my post on UI Testing.
Upvotes: 3