【问题标题】:Click on first instance of items单击项目的第一个实例
【发布时间】:2017-07-24 22:26:52
【问题描述】:

我正在尝试单击“最近”,但实例太多,我不知道该怎么做。

Find: Descendants matching type StaticText
  Output: {
    StaticText 0x60800036da40: traits: 8590000192, {{0.0, 77.0}, {330.0, 2.0}}, label: 'Details'
    StaticText 0x60800036df80: traits: 8589934656, {{40.0, 90.0}, {211.0, 21.0}}, identifier: 'navScreenTitle', label: 'Speaker'
    StaticText 0x60800036dd40: traits: 8589934656, label: 'No Volume Available'
    StaticText 0x60800036e040: traits: 8589934656, {{40.0, 90.0}, {211.0, 21.0}}, identifier: 'navScreenTitle', label: 'Speaker'
    StaticText 0x60800036e100: traits: 8589934656, label: 'No Volume Available'
    StaticText 0x60800036e1c0: traits: 8589934656, {{40.0, 90.0}, {211.0, 21.0}}, identifier: 'navScreenTitle', label: 'Speaker'
    StaticText 0x60800036e280: traits: 8589934656, label: 'No Volume Available'
    StaticText 0x60800036e340: traits: 8589934656, {{40.0, 90.0}, {211.0, 21.0}}, identifier: 'navScreenTitle', label: 'Speaker'
    StaticText 0x60800036e400: traits: 8589934656, label: 'No Volume Available'
    StaticText 0x60800036e580: traits: 8589934656, {{40.0, 178.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Status'
    StaticText 0x60800036e640: traits: 8589934656, {{177.0, 178.0}, {118.0, 21.0}}, label: 'Available'
    StaticText 0x60800036e700: traits: 8589934656, {{40.0, 178.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Status'
    StaticText 0x60800036e7c0: traits: 8589934656, {{177.0, 178.0}, {118.0, 21.0}}, label: 'Available'
    StaticText 0x60800036e880: traits: 8589934656, {{40.0, 178.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Status'
    StaticText 0x60800036e940: traits: 8589934656, {{177.0, 178.0}, {118.0, 21.0}}, label: 'Available'
    StaticText 0x60800036ea00: traits: 8589934656, {{40.0, 178.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Status'
    StaticText 0x60800036eac0: traits: 8589934656, {{177.0, 178.0}, {118.0, 21.0}}, label: 'Available'
    StaticText 0x60800036ec40: traits: 8590000192, {{0.0, 211.0}, {330.0, 2.0}}, label: 'Conversations'
    StaticText 0x60800036edc0: traits: 8589934656, {{40.0, 224.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Recents'
    StaticText 0x60800036ee80: traits: 8589934656, {{40.0, 224.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Recents'
    StaticText 0x60800036ef40: traits: 8589934656, {{40.0, 224.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Recents'
    StaticText 0x60800036f000: traits: 8589934656, {{40.0, 224.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Recents'
    StaticText 0x60800036f180: traits: 8589934656, {{40.0, 268.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Contacts'
    StaticText 0x60800036f240: traits: 8589934656, {{40.0, 268.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Contacts'
    StaticText 0x60800036f300: traits: 8589934656, {{40.0, 268.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Contacts'
    StaticText 0x60800036f3c0: traits: 8589934656, {{40.0, 268.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Contacts'
    StaticText 0x60800036f540: traits: 8589934656, {{40.0, 312.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Ch'
    StaticText 0x60800036f600: traits: 8589934656, {{40.0, 312.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Ch'
    StaticText 0x60800036f6c0: traits: 8589934656, {{40.0, 312.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Ch'
    StaticText 0x60800036f780: traits: 8589934656, {{40.0, 312.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Ch'
    StaticText 0x60800036f900: traits: 8590000192, {{0.0, 345.0}, {330.0, 2.0}}, label: 'Options'
    StaticText 0x60800036fa80: traits: 8589934656, {{40.0, 358.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Options'
    StaticText 0x60800036fb40: traits: 8589934656, {{40.0, 358.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Options'
    StaticText 0x60800036fc00: traits: 8589934656, {{40.0, 358.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Options'
    StaticText 0x60800036fcc0: traits: 8589934656, {{40.0, 358.0}, {257.0, 21.0}}, identifier: 'navScreenTitle', label: 'Options'
    StaticText 0x6080003708c0: traits: 8589934656, {{379.0, 69.0}, {319.0, 18.0}}, label: 'echo'
    StaticText 0x608000370980: traits: 8589934656, {{398.0, 92.0}, {294.0, 16.0}}, label: 'Talk to me to test your audio'
    StaticText 0x608000370bc0: traits: 8589934656, {{379.0, 122.0}, {319.0, 18.0}}, label: 'Test user'
    StaticText 0x608000370c80: traits: 8589934656, {{398.0, 145.0}, {294.0, 16.0}}, label: 'Standby'
  }

如何点击标签的第一个实例Recents 标签是在运行时动态填充的,我没有特定的标识符来点击它。

【问题讨论】:

    标签: objective-c xcode8 xcode-ui-testing


    【解决方案1】:

    您可以使用element(boundBy: Int) 访问某个索引处的元素

    XCUIApplication().staticTexts.matching(identifier: "Recents").element(boundBy: 0)
    

    或在 Objective-C 中

    [[[[[XCUIApplication alloc] init] staticTexts] matchingIdentifier:@"Recents"] elementBoundByIndex:0];
    

    【讨论】:

    • 我试图在 Objective-C 中做同样的事情,但我没有做到。如何在 Objective-C 中完成同样的任务?
    • 指向正确的方向@Titouan de Bailleul 这有效:[[[[app staticTexts] matchingIdentifier:@"Recents"]elementBoundByIndex:0]tap];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2019-09-25
    • 2016-04-23
    • 2016-12-15
    • 1970-01-01
    相关资源
    最近更新 更多