In EarlGrey how can I access the element object that I am interacting with, for example I want access to UIButton that I just tapped.
Asked
Active
Viewed 411 times
1 Answers
3
EarlGrey does not return (pointers to) elements as the view/element returned may not be around after the interaction is complete, moreover it can lead to hard to detect errors as holding strong references to views can modify the view's lifecycle. You can however get access to the element while the interaction is happening using GREYActionBlock.
- (void)testFoo {
[[EarlGrey selectElementWithMatcher:grey_FooElementMatcher()]
performAction:[GREYActionBlock actionWithName:@"bar"
performBlock:^(id element, NSError *__strong *errorOrNil) {
[element doWhatever];
return YES; // Return YES for success, NO for failure.
}
]];
}

Zheng Xu
- 101
- 6