【问题标题】:How to access a UIATableCell within the app window using UIAutomation in Instruments?如何使用 Instruments 中的 UIAutomation 在应用程序窗口中访问 UIATableCell?
【发布时间】:2012-05-31 19:17:50
【问题描述】:

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

我无法访问此按钮,但我尝试了。谁能帮助我如何访问此按钮?

【问题讨论】:

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


    【解决方案1】:

    试试这个:

        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();
    

    【讨论】:

    • 如果我使用mainWindow().cells() ,它会给出无效元素错误。 UIAutomation 似乎无法识别单元格是窗口的直接子级。但是我使用了mainWindow().elements()[textInCell].buttons()[textInCell].tap() ,这似乎有效。仍然很奇怪,我想知道为什么 UIAutomation 无法识别这一点?感谢您的回复!
    • 根据您在上面发布的 logElementTree 屏幕截图 - 'cell' 应该在那里。尝试找出它是什么类型的元素。可能是 UIAutomation 问题。 ...logMessage(mainWindow().elements()[textInCell].toString());它应该记录类似 [object UIA]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    • 2014-11-26
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    相关资源
    最近更新 更多