UI测试NSPredicate用于单元格staticTexts

a d*_*per 1 xcode objective-c ui-testing nspredicate xcode-ui-testing

我正在创建一个XCUIElementQuery来获取所有具有staticTexts的单元格以字符串开头(例如"Buy"),但不知道.我用谷歌搜索但没有希望.

绝望的尝试得到staticText但不是cell.

    XCUIElementQuery *rows = [app.cells.staticTexts matchingPredicate:[NSPredicate predicateWithFormat:@"label CONTAINS 'Buy'"]];
Run Code Online (Sandbox Code Playgroud)

有经验的人吗?我们parent至少可以得到上面的staticTexts吗?

Nic*_*ell 6

我发现这个有效:

XCUIElementQuery *rows = 
   [app.cells containingPredicate:
        [NSPredicate predicateWithFormat:@"label CONTAINS 'Buy'"]];
Run Code Online (Sandbox Code Playgroud)

如果您使用app.cells.staticTexts,您将获得标签而非单元格的查询.另外请确保您使用的是官方Xcode 7. Beta可能是错误的.