Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAutomation - different results from Instruments and Command Line

When I run a UIAutomation script in Instruments, everything works fine but when I run the exact same script from the command line, I get this error : Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().tableViews()[0].cells()["ID number, Required"].textFields()[0]

Here is the Instruments command I'm using to launch the test

instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/johan/Library/Developer/Xcode/DerivedData/Brokers-etvmwznhcjprybdekgtixzzsnbrw/Build/Products/Release-iphonesimulator/MyApp -e UIASCRIPT /Users/johan/Desktop/Script.js 
like image 998
Johan de Klerk Avatar asked Nov 12 '22 13:11

Johan de Klerk


1 Answers

The reason might be that UIAutomation under instruments is much slower than when run from the command line. So it might be that under instruments the element target.frontMostApp().mainWindow().tableViews()[0].cells()["ID number, Required"].textFields()[0]
exists, i.e. is valid, but from the console not yet.
Maybe you should try to wait for the element to become valid, before you perform an action on it, of to check its validity (isValid) and log it to be sure about its status.

like image 163
Reinhard Männer Avatar answered Nov 15 '22 05:11

Reinhard Männer