用于在 UItableView 中设置文本字段值的 UIAutomation 脚本

UIAutomation script for setting textfield values in UItableView

我是 UIAutomation 的新手,我正在尝试向 UITabelView 中的两个文本字段输入值。

我试过的脚本如下

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

target.delay(1);

var tableView = window.tableViews()[0];

tableView.logElementTree();

var cellOne = tableView.cells()[0].textFields()[0].setValue(“username”);
var cellTwo = tableView.cells()[1].textFields()[0].setValue(“password”);

始终输入第一个单元格中的文本字段,但第二个单元格总是失败。当我尝试记录它的元素树时 returns UIElementNil

我的脚本有问题吗?

我仔细阅读了 Apple 关于自动化的文档 UI 测试并遵循了将手动用户界面操作记录到自动化脚本中,并且 Instruments 根据我的手动操作为我创建了脚本。

如果有人像我一样被打动并且像我一样愚蠢而不去阅读 Apple 的文档。请不要那样做,始终首先参考 Apple 的文档。

这是参考文献

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

这是我的脚本

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

window.buttons()["Login"].tap();

target.delay(1);

var tableView = window.tableViews()[0];

tableView.cells()[0].textFields()[0].textFields()[0].setValue("username");

tableView.cells()[1].secureTextFields()[0].secureTextFields()[0].setValue("password");

window.navigationBar().rightButton().tap();

如您所见,我没有注意到密码文本字段是一个安全文本字段。