swift - 访问 XCUIElement 中的最后一个元素

标签 swift xcode coded-ui-tests xcuitest

在我的 UI 测试中,我有这个 XCUIElement :

XCUIApplication().staticTexts["提交订单"]

当我打印 debugDescription 时:

po print(XCUIApplication().staticTexts["SUBMIT ORDER"].debugDescription)

有两个元素匹配:

Find: Elements matching predicate '"SUBMIT ORDER" IN identifiers'
      Output: {
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
      }

我的问题是:如何只在最后一个元素上制作 .tap()

最佳答案

您可以使用:

XCUIApplication().staticTexts.matching(identifier: "SUBMIT ORDER").allElementsBoundByIndex.last

关于swift - 访问 XCUIElement 中的最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59180278/

相关文章:

testing - 无需安装 Visual Studio 的编码 UI 测试

ios - 使用 Parse 框架的 Xcode 6 Playground ?

ios - Swift:实例成员不能用于 ARKitVision 示例中的类型

ios - 为搜索栏委托(delegate)赋值 - Swift

ios - 核心数据 - 关系、获取和插入

c# - 无法使用 CodedUI 从组合框中选择数据

ios - IGListKit:获取当前可见的单元格索引

ios - El capitane 上的 Xcode 6.2 - Storyboard编译器错误 : Exception while running ibtool

ios - 更新到 Swift 4.2 后的 Xcode 构建错误 - 体系结构 arm64 的 undefined symbol

random - 有没有办法让 MsTest/Coded UI 测试每次都以新的随机顺序运行?