我如何 select UITests 中的 UITableView 的一部分?
How can I select one section of a UITableView in UITests?
我有一个显示某些部分的 TableView。当用户点击这些部分时,每个部分下方的单元格都会出现。
我要select一段模拟触摸
尝试使用谓词
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];
如果你给你的部分 headers 一个无障碍标识符。如果您的部分 headers 是动态的,您可以为它们提供相同的可访问性标识符,然后按索引选择一个:
XCUIElement *table = [app.tables elementBoundByIndex: 0];
XCUIElementQuery *sections = [table.otherElements matchingIdentifier: "MySection"];
XCUIElement *section = [sections elementBoundByIndex: 0];
[section tap];
否则,您可以直接通过可访问性标识符访问:
XCUIElement *section = table.otherElements["MySection"];
我有一个显示某些部分的 TableView。当用户点击这些部分时,每个部分下方的单元格都会出现。
我要select一段模拟触摸
尝试使用谓词
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];
如果你给你的部分 headers 一个无障碍标识符。如果您的部分 headers 是动态的,您可以为它们提供相同的可访问性标识符,然后按索引选择一个:
XCUIElement *table = [app.tables elementBoundByIndex: 0];
XCUIElementQuery *sections = [table.otherElements matchingIdentifier: "MySection"];
XCUIElement *section = [sections elementBoundByIndex: 0];
[section tap];
否则,您可以直接通过可访问性标识符访问:
XCUIElement *section = table.otherElements["MySection"];