Skip to content

Instantly share code, notes, and snippets.

@wearhere
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wearhere/3dc3f0306489adafe3b2 to your computer and use it in GitHub Desktop.
Save wearhere/3dc3f0306489adafe3b2 to your computer and use it in GitHub Desktop.
Workaround for `UIAElement.isEnabled` sometimes returning false positives.
diff --git a/Sources/Classes/UIAutomation/User Interface Elements/SLElement.m b/Sources/Classes/UIAutomation/User Interface Elements/SLElement.m
index 375cba2..2cac09a 100644
--- a/Sources/Classes/UIAutomation/User Interface Elements/SLElement.m
+++ b/Sources/Classes/UIAutomation/User Interface Elements/SLElement.m
@@ -362,6 +362,22 @@ UIAccessibilityTraits SLUIAccessibilityTraitAny = 0;
return isVisible;
}
+- (BOOL)isEnabled {
+ __block BOOL isEnabled = [super isEnabled];
+
+ // sometimes UIAutomation says that a button is enabled when it's not, so we double check if possible
+ // (with no timeout--`isEnabled` should evaluate the current state of the element)
+ if (isEnabled) {
+ [self examineMatchingObject:^(NSObject *object) {
+ if ([object respondsToSelector:@selector(isEnabled)]) {
+ isEnabled = [(id)object isEnabled];
+ }
+ } timeout:0.0];
+ }
+
+ return isEnabled;
+}
+
#pragma mark -
- (void)tapAtActivationPoint {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment