5

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 
Johan de Klerk
  • 2,515
  • 3
  • 25
  • 35
  • Can you post the instruments command you're using to launch the test? Perhaps there's a difference of some kind in the environment the command line is launching versus the one used by the Instruments GUI app. – Bill Agee Jan 08 '13 at 04:02
  • What is the Xcode version? A similar command seems to work for me in Xcode 4.5.2, with my build configuration set to Release and the iPhone 6.0 simulator as the destination. Maybe try switching your scheme to the Debug build configuration, build, then replace "Release-iphonesimulator" in your instruments command with "Debug-iphonesimulator"? – Bill Agee Jan 10 '13 at 08:29

1 Answers1

1

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.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116