ios - 为什么 UIAElement 的 child 不等于自己?

标签 ios xcode instruments ios-ui-automation

我注意到一段时间前编写的 UIAutomation 脚本中有一些奇怪的行为,但我已经有一段时间没有运行了。我的断言失败了;在进行一些挖掘之后,我发现在迭代 UIAElement 的 .elements() 时,子元素似乎与它们自身不相等。

这在过去对我有用,但至少在 XCode 4.3.2 中似乎被破坏了

重现:

  1. 创建单 View 应用
  2. 在 View 中添加一些元素,在元素上设置辅助功能标签,以便 UIAutomation 能够拾取它们
  3. 在 UIAutomation 中运行以下脚本:

    var elements = UIATarget.localTarget().frontMostApp().mainWindow().elements();
    for (var i = 0; i < elements.length; i++) {
      var el1 = elements[i];
      var el2 = elements[i];
      var equals = (el1 == el2);
      UIALogger.logMessage(el1.label() + " is equal to " + el2.label() + " ? " + equals);
    }
    
  4. 看到 el1el2 似乎没有引用同一个对象。

我不确定这是否是预期的行为,尽管这对我来说似乎很不对劲。如果有人有任何见解,我将不胜感激。

最佳答案

不确定这是否有帮助,但您可以尝试使用 === 运算符来比较对象吗?

关于ios - 为什么 UIAElement 的 child 不等于自己?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12100928/

相关文章:

xcode - TVOS 自动化

xcode - 我如何阅读仪器?

ios - 在 UISearchController 中实现 updateSearchResultsForSearchController 时遇到问题?

ios - 获取 SwiftUI 中 List 的内容偏移量

c++ - ld : entry point (start) undefined. 通常在 crt1.o 中用于架构 x86_64

xcode - 有条件地中止发布版本

ios - 是否可以知道 QLPreviewController 何时到达文档末尾?

ios - 谷歌分析 ios sdk V2.0 短 session 持续时间

ios - 缺少 xcode dylib 动态库文件

ios - 仪器的程序控制(或注释)?