3

So in my nib file i enabled accessibility and set the accessibility label of a textfield to "txt" I am trying to find this textfiled based on accessibility name and change its text.

var target = UIATarget.localTarget();
var application = target.frontMostApp(); 
var mainWindow = application.mainWindow();
mainWindow.logElementTree();

// This works
var textField = mainWindow.textFields()[0];

//this doesn't work
var textField = mainWindow.textFields()["txt"];

textField.setValue("Hello");

Am I doing anything wrong? How can I find a label based on accessibility label?

EDIT:

I am open to other solutions as well, I am trying to avoid getting the textfield based on the index

aryaxt
  • 76,198
  • 92
  • 293
  • 442
  • 1
    What your logElementTree shows for this texfield name? – jki Nov 29 '11 at 20:11
  • It works fine after setting the accessibilityLebel in the code. But why it doesn't work when it is set in the Interface Builder? Could u give any details? –  Jan 11 '12 at 10:31

1 Answers1

5

I have a similar problem and setting the accessibility label value in the code instead in the nib file solve my problem. For example, I have a UITextField that I need to access in my UIAutomation script, I would have to set the accessibility label value in the viewDidLoad method as shown below.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    testTxtField.accessibilityLabel = @"myTxtBox";
}

and below is my UIAutomation Script

var target = UIATarget.localTarget();
var application = target.frontMostApp(); 
var mainWindow = application.mainWindow();
mainWindow.logElementTree();

// This works
//var textField = mainWindow.textFields()[0];

// Now, this work too.
var textField = mainWindow.textFields()["myTxtBox"];
textField.setValue("Hello");

UIALogger.logMessage("Text field:" + textField.label());
Ken W
  • 999
  • 7
  • 10