如何使用仪器中的UIAutomation访问应用程序窗口中的UIATableCell?

时间:2012-05-31 19:17:50

标签: ios automated-tests functional-testing ios-ui-automation

我有这个应用程序,我正在使用Apple提供的UIAutomation框架编写自动化测试脚本。在我的应用中,我想点按一个按钮,该按钮是UIATableCell()的孩子,而该按钮又是我应用的mainWindow()的孩子。当我运行命令logElementTree()时,显示以下内容: enter image description here

我尝试不能访问此按钮。有谁可以帮我如何访问这个按钮?

1 个答案:

答案 0 :(得分:0)

试试这个:

    var buttonToTap = mainWindow().cells()[0].buttons()[0].tap();
    if ( buttonToTap.checkIsValid() )
        buttonToTap.tap();

如果您尝试点击的单元格中的文本在应用程序运行期间不会更改,您可以尝试使用对象名称而不是索引:

var textInCell = "You have not talked to anyone named 'Bugles'";    
var buttonToTap = mainWindow().cells()[textInCell].buttons()[textInCell].tap();
if ( buttonToTap.checkIsValid() )
    buttonToTap.tap();