How do I check whether an element exists in the UI hierarchy? I dont want EarlGrey to fail if an element does not exist but just check if its there, I need this for UITableView where I must constantly scroll to top and scroll down searching an element but the element is sometimes already on the current view to begin with.
Asked
Active
Viewed 1,071 times
1 Answers
4
EarlGrey supports Error API: when EarlGrey APIs take an NSError reference the APIs will not throw when they fail instead they fill the error reference with the corresponding error. For example, use this code to check if an element exists in the view hierarchy (and act on that information):
NSError *error;
[[EarlGrey selectElementWithMatcher:grey_fooElementMatcher()]
assertWithMatcher:grey_notNil() error:&error];
if (error && [error.domain isEqual:kGREYInteractionErrorDomain] &&
error.code == kGREYInteractionElementNotFoundErrorCode) {
// Element doesn’t exist.
} else if (!error) {
// Element exists.
}

Gautam
- 286
- 1
- 3