【问题标题】:How can I select one section of a UITableView in UITests?如何在 UITests 中选择 UITableView 的一部分?
【发布时间】:2017-02-12 19:06:27
【问题描述】:

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

我想选择一个部分来模拟触摸

尝试使用谓词

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];

【问题讨论】:

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


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多