-
-
Notifications
You must be signed in to change notification settings - Fork 67
Add partial xpath support to ignore identifiers in the axpath #110
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,10 @@ @interface AfMSessionController() | |
| @property BOOL isAltKeyDown; | ||
| @property BOOL isCommandKeyDown; | ||
|
|
||
| // Properties for partial AXPath fix | ||
| @property NSString* elementRole; | ||
| @property NSMutableDictionary* predicateDict; | ||
|
|
||
| // Properties for handling timed events such as mouse moves. | ||
| @property NSMutableArray *timedEvents; | ||
| @property NSUInteger timedEventIndex; | ||
|
|
@@ -1114,6 +1118,13 @@ - (NSArray *)findAllUsingAbsoluteAXPath:(NSString *)axPath | |
| } | ||
| } | ||
|
|
||
| // See if there is any partially matching XPath | ||
| if ([matchedNodes count] == 0) | ||
| { | ||
| matchedNodes = [self findAllUsingPartialAXPath:axPathComponents rootUIElement:self.currentApplication]; | ||
| } | ||
| [self clearCurrentElementCache]; | ||
|
|
||
| return matchedNodes; | ||
| } | ||
|
|
||
|
|
@@ -1190,6 +1201,107 @@ - (NSArray *)findAllUsingAXPathComponents:(NSArray *)axPathComponents rootUIElem | |
| return @[]; | ||
| } | ||
|
|
||
| -(PFUIElement*) findElementRecursively:(PFUIElement *)rootUIElement calls:(int)calls | ||
| { | ||
| if ([self checkIfElementFound:rootUIElement]) | ||
| { | ||
| return rootUIElement; | ||
| } | ||
| calls++; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what the |
||
|
|
||
| NSArray* children = rootUIElement.AXChildren; | ||
|
|
||
| PFUIElement* result = nil; | ||
|
|
||
| if (children) | ||
| { | ||
| for (PFUIElement* node in children) | ||
| { | ||
| result = [self findElementRecursively:node calls:calls]; | ||
| if (result) | ||
| { | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| calls--; | ||
| return nil; | ||
| } | ||
|
|
||
| -(NSArray*) findAllUsingPartialAXPath:(NSArray *)axPathComponents rootUIElement:(PFUIElement *)rootUIElement | ||
| { | ||
| NSArray* childUIElements = rootUIElement.AXChildren; | ||
|
|
||
| if (!childUIElements || [childUIElements count] == 0) | ||
| { | ||
| return @[]; | ||
| } | ||
|
|
||
| [self setRoleAndPredicatesOfElement:[axPathComponents lastObject]]; | ||
| NSMutableArray *matchedChildren = [NSMutableArray array]; | ||
| PFUIElement* foundElement = [self findElementRecursively:rootUIElement calls:0]; | ||
|
|
||
| if ([foundElement isNotEqualTo:nil]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cannot we simply use |
||
| { | ||
| [matchedChildren addObject:foundElement]; | ||
| } | ||
|
|
||
| return matchedChildren; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. matchedChildren.copy |
||
| } | ||
|
|
||
| -(void) setRoleAndPredicatesOfElement:(NSString*) elementToFind | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class seems overloaded with different stuff. Would it be possible to extract lookup-specific stuff into a separate class/category? Even better, add some basic unit tests to it? |
||
| { | ||
| if (self.elementRole && self.predicateDict) { | ||
| return; | ||
| } | ||
|
|
||
| NSDictionary *parseElement = [self parseRoleAndPredicateString:elementToFind]; | ||
|
|
||
| self.elementRole = parseElement[kNodeRole]; | ||
| self.predicateDict = [[NSMutableDictionary alloc] init]; | ||
|
|
||
| NSArray* predicateArray = parseElement[kNodePredicate][kPredicateOperations]; | ||
|
|
||
| for (int i=0; i < [predicateArray count]; i++) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cannot we simple iterate over array items (for-in)? |
||
| { | ||
| id object = [predicateArray objectAtIndex:i]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to have better name for this variable? |
||
| NSString* attributeName = object[kPredicateAttributeName]; | ||
| NSString* attributeValue = object[kPredicateAttributeValue]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. attributeValue only should be extracted inside of |
||
| if (![attributeName isEqualToString:@"AXIdentifier"]) | ||
| { | ||
| self.predicateDict[attributeName] = attributeValue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| -(void) clearCurrentElementCache | ||
| { | ||
| self.elementRole = nil; | ||
| self.predicateDict = nil; | ||
| } | ||
|
|
||
| -(BOOL) checkIfElementFound:(PFUIElement*) currentElement | ||
| { | ||
|
|
||
| if ([currentElement.AXRole isNotEqualTo:self.elementRole]) | ||
| { | ||
| return NO; | ||
| } | ||
|
|
||
| for( NSString* key in self.predicateDict ) | ||
| { | ||
| if ( ![currentElement existsAttribute:key] || [self.predicateDict[key] isNotEqualTo:[currentElement valueForAttribute:key]]) | ||
| { | ||
| return NO; | ||
| } | ||
| } | ||
|
|
||
| return YES; | ||
|
|
||
| } | ||
|
|
||
| - (BOOL)element:(PFUIElement *)uiElement doesMatchPredicate:(NSDictionary *)predicate atIndex:(NSUInteger)elementIndex | ||
| { | ||
| BOOL doesMatch = NO; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it always make sense to mention nullability in method signatures