ios - 如何在 UITests 中选择 UITableView 的一部分?

标签 ios objective-c uitableview xcode-ui-testing

我有一个显示一些部分的 TableView。当用户点击这些部分时,每个部分下方的单元格都会出现。

我要选择一个section来模拟触摸

尝试使用谓词

XCUIApplication* app = [[XCUIApplication alloc] init];
[app launch];
XCUIElement* section = [app.tables elementMatchingPredicate: [NSPredicate predicateWithFormat: @"description like MySection"]];
[section tap];

试图访问我的 TableView 上的第一个单元格,但没有成功。

XCUIElement* section = [app.tables elementBoundByIndex:0];
[section tap];

最佳答案

如果您为节标题提供辅助功能标识符。如果您的部分标题是动态的,您可以为它们提供相同的可访问性标识符,然后按索引选择一个:

XCUIElement *table = [app.tables elementBoundByIndex: 0];
XCUIElementQuery *sections = [table.otherElements matchingIdentifier: "MySection"];
XCUIElement *section = [sections elementBoundByIndex: 0];
[section tap];

否则,您可以直接通过可访问性标识符访问:

XCUIElement *section = table.otherElements["MySection"];

关于ios - 如何在 UITests 中选择 UITableView 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42191940/

相关文章:

iphone - UITableView 普通样式部分标题在搜索 View 上重绘

objective-c - CGContextStrokePath 在 iOS > 5 中触发 EXC_BAD_ACCESS

c# - Xamarin C# 一个 UITableView 中的两个 UITableViewCells

ios - CoreGraphics (drawRect) 用于在 UITableViewCell 中绘制标签和 UIImageView

ios - 在 swift xcode 数组中打印特定字符串时崩溃

ios - SwiftUI 如何在 PageTabViewStyle 中跟踪页面索引?

objective-c - iOS:在 View 之间传递数据

ios - UICollectionView 和它的 collectionViewLayout 之间是否存在保留周期?

ios - 如何用透明描边保存图像

ios - 如何模仿 UITableView 的 UITableViewStylePlain section header 样式