square/KIF — Issue #99: Crash on [elementStack addObject:subelement];
Author: paweldudek
Created: 2011-12-08 09:00:21+00:00
State: open

I have a step that taps Cancel button on UISearchBar right after a step that taps the clear button has been tapped. KIF looks for the given view in the

[UIView(KIFAdditions) accessibilityElementMatchingBlock:]

method.
Line 160 is the place where exception is thrown - seems that

UIAccessibilityElement *subelement = [element accessibilityElementAtIndex:accessibilityElementIndex];

method returns nil objects, which is then inserted into an array - this obviously causes a crash. Adding a simple check if the object is not nil resolves the issue.

if (subelement) {
[elementStack addObject:subelement];
}