It's hard for me to get the interface elements by name in a UIAutomation script.
I set the accessibility bar for the text control:

And I know that I have the correct parent view, since this code will work to set the contents of the field:
var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
textfields[0].setValue("testuser");
Unfortunately, if I try to access the field by name, as the docs seem to indicate that I should do this, I get an error:
var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
textfields['foo'].setValue("testuser");
Cannot perform an action on an invalid element: UIAElementNil from target.frontMostApp (). mainWindow (). textFields () ["foo"]
Does anyone know why the search by name function doesn't work here for me?
Thank you for understanding!