2

I have the following items in logElementTree output:

UIAButton: rect:{{20, 427}, {41, 41}}

UIAButton: rect:{{140, 427}, {41, 41}}

These buttons have no identifier, no name, and are not drawn in XIB. On my automation test script I only use index (something like target.frontMostApp().mainWindow().buttons()[7].tap())

But then, this line will not always work because index is changing. I just want to ask, if there's a way to tap this button other than using index? Please note that the button has no name, so I cannot use buttons()["name'"].tap()

iHunter
  • 6,205
  • 3
  • 38
  • 56

1 Answers1

0

Technically this would be the best way to go about doing what you would like, so I'll leave it here for other developers who see this question. In your case since you have limited technical experience, I would recommend asking your developer to assign ids or names to buttons. Providing good names for buttons and other UI elements means that your app is also accessible for those users with impaired eyesight, since voiceover will read them the names you've given to your buttons. The following block of code will programmatically assign a label and a accessibility hint to a dynamically created object that conforms to UIAccessibility.

From Apple's documentation (in this case they're doing it on a view, but you could do it on any object like a button):

- (id)init
{
  _view = [[[MyCustomView alloc] initWithFrame:CGRectZero] autorelease];
  [_view setIsAccessibilityElement:YES];

  [_view setAccessibilityTraits:UIAccessibilityTraitButton];
  [_view setAccessibilityLabel:NSLocalizedString(@"view.label", nil)];
  [_view setAccessibilityHint:NSLocalizedString(@"view.hint", nil)];
}

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iPhoneAccessibility/Making_Application_Accessible/Making_Application_Accessible.html#//apple_ref/doc/uid/TP40008785-CH102-SW5

Javascript "hack" (not very clean, but it works...):

var window = UIATarget.localTarget(); 
window.tap({x:yourXCoordinateHere , y:yourYCoordinateHere});
Jack Lawrence
  • 10,664
  • 1
  • 47
  • 61
  • Thank you for the answer, but I am not really good at programming, I'm a tester who likes to try automation, so your answer is quite not clear to me. I only want to know if there's a way to tap a button (no id/name) rather than using index. Thanks again. – user1140194 Jan 11 '12 at 08:35
  • 1
    From your answer I'm assuming that you mean you'd rather stay on the side of some javascript, correct? I'll update my answer accordingly. – Jack Lawrence Jan 12 '12 at 03:10