UIAutomation - 仪器和命令行的不同结果

Joh*_*erk 5 iphone command-line instruments ui-automation ios-ui-automation

当我在Instruments中运行UIAutomation脚本时,一切正常,但是当我从命令行运行完全相同的脚本时,我收到此错误: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().tableViews()[0].cells()["ID number, Required"].textFields()[0]

这是我用来启动测试的Instruments命令

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 
Run Code Online (Sandbox Code Playgroud)

Rei*_*ner 1

原因可能是仪器下的 UIAutomation 比从命令行运行时慢得多。因此,在仪器下,元素 target.frontMostApp().mainWindow().tableViews()[0].cells()["ID number, required"].textFields()[0] 可能
存在,即有效,但从控制台来看还没有。
也许您应该尝试等待元素变得有效,然后再对其执行操作,检查其有效性 (isValid) 并记录它以确保其状态。