diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBResolve.m b/WebDriverAgentLib/Categories/XCUIElement+FBResolve.m index 16b5eb190..f52c72bf6 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBResolve.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBResolve.m @@ -47,9 +47,7 @@ - (XCUIElement *)fb_stableInstance if (nil == uid) { return self; } - NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id snapshot, NSDictionary *bindings) { - return [[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot] isEqualToString:uid]; - }]; + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K = %@",FBStringify(FBXCElementSnapshotWrapper, fb_uid), uid]; return [query matchingPredicate:predicate].allElementsBoundByIndex.firstObject ?: self; } diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBUID.m b/WebDriverAgentLib/Categories/XCUIElement+FBUID.m index 1af09a4ec..06979a4cf 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBUID.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBUID.m @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +#import + #import "XCUIElement+FBUID.h" #import "FBElementUtils.h" @@ -33,6 +35,17 @@ - (NSString *)fb_uid @implementation FBXCElementSnapshotWrapper (FBUID) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-load-method" ++ (void)load +{ + Class XCElementSnapshotCls = objc_lookUpClass("XCElementSnapshot"); + NSAssert(XCElementSnapshotCls != nil, @"Could not locate XCElementSnapshot class"); + Method uidMethod = class_getInstanceMethod(self.class, @selector(fb_uid)); + class_addMethod(XCElementSnapshotCls, @selector(fb_uid), method_getImplementation(uidMethod), method_getTypeEncoding(uidMethod)); +} +#pragma diagnostic pop + - (unsigned long long)fb_accessibiltyId { return [FBElementUtils idWithAccessibilityElement:self.accessibilityElement]; @@ -45,7 +58,10 @@ + (nullable NSString *)wdUIDWithSnapshot:(id)snapshot - (NSString *)fb_uid { - return [self.class wdUIDWithSnapshot:self.snapshot]; + if ([self isKindOfClass:FBXCElementSnapshotWrapper.class]) { + return [self.class wdUIDWithSnapshot:self.snapshot]; + } + return [FBElementUtils uidWithAccessibilityElement:[self accessibilityElement]]; } @end diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m index bd8c8135c..d78cfd99e 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m @@ -162,10 +162,10 @@ @implementation XCUIElement (FBUtilities) XCUIElementQuery *query = onlyChildren ? [self.fb_query childrenMatchingType:type] : [self.fb_query descendantsMatchingType:type]; - NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id snapshot, NSDictionary *bindings) { - return [matchedIds containsObject:[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot] ?: @""]; - }]; + + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K IN %@",FBStringify(FBXCElementSnapshotWrapper, fb_uid), matchedIds]; [matchedElements addObjectsFromArray:[query matchingPredicate:predicate].allElementsBoundByIndex]; + for (XCUIElement *el in matchedElements) { el.fb_isResolvedNatively = @NO; }