IOS Instruments Automation "setValue" not working

I just want to test my iOS interface using UI Automation, but I got stuck when it came to entering text into UITextFields. The documentation says that the "setValue (...)" method should do the trick, but that is not the case.

I always get this error:

Script threw an uncaught JavaScript error: Unexpected error in -[UIATextField_0x9952690 setValue:], /SourceCache/UIAutomation_Sim/UIAutomation-271/Framework/UIAElement.m line 1142, kAXErrorSuccess on line 15 of login.js, #0 setValue() 

The code is as follows:

 var textfields = UIATarget.localTarget().frontMostApp().mainWindow().textFields(); username = textfields["username"]; username.setValue("test"); 

The username field is not null or undefined.

My second solution was a JS project: https://github.com/alexvollmer/tuneup_js#readme It has a "typeString" method for text fields, but it is a bit buggy and does not work when a number and capital letters are entered.

I work with iOS6.1, Tools Version 4.6 (46000), Xcode Version 4.6 (4H127).

Any help is appreciated!

+6
source share
2 answers

Check if below works

target.delay (1); .... UIATarget.localTarget () frontMostApp () MainWindow () TextFields () ["username"] click (); target.delay (1); UIATarget.localTarget () frontMostApp () MainWindow () TextFields () ["username"] SetValue ("test"); ....

Check if the hierarchy is correct if it does not work for you.

+10
source

I came here trying to understand how the UI Automation script works, since the documentation and code are really missing (or written from a very specific point of view that does not explain all cases).

Here are two things I learned about this subject:

  • First of all, you must enable the accessibility of the item. I turned it off in my tests, and everything behaved very strange until I turned it on (getting a similar "unexpected error" like you). Therefore, make sure the Availability feature is enabled. But note that some things still work with it. For example, you can still find an element by name (accessibilityIdentifier), but you cannot click it or call setValue() .

enter image description here

  1. You need to scan the application hierarchy. My guess was that providing the accessibilityIdentifier element would allow me to simply find the element with an identifier such as HTML getElementById . But this is not at all true. You must dig the hierarchy level by level, even when using the accessibilityIdentifier. Fortunately, you can use UIAElement.logElementTree() to get some hints about the correct hierarchy to use.

So far I am not impressed with this structure, but I am moving so slowly.

0
source

All Articles