简体   繁体   English

为什么UIAElement的孩子不等于自己?

[英]Why are UIAElement's children not equal to themselves?

I noticed some weird behavior in a UIAutomation script I had written a while back that I hadn't ran in a while. 我注意到UIAutomation脚本中有一些奇怪的行为,我曾经写过一段时间我没有跑过。 My assertions were failing; 我的断言失败了; after doing some digging, I saw that when iterating a UIAElement's .elements() , subelements do not appear to be equal to themselves. 在做了一些挖掘之后,我看到在迭代UIAElement的.elements() ,子元素看起来并不等于它们自己。

This has worked for me as expected in the past, but appears to be broken in at least XCode 4.3.2 这对我来说在过去是如此的预期,但至少在XCode 4.3.2中似乎被打破了

To repro: 重申:

  1. create a single-view app 创建一个单一视图的应用程序
  2. throw some elements in the view, set Accessibility Labels on the elements so they get picked up by UIAutomation 在视图中抛出一些元素,在元素上设置“辅助功能标签”,以便UIAutomation选择它们
  3. Run the following script in UIAutomation: 在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. See that el1 and el2 do not appear to reference the same object. 看到el1el2似乎没有引用同一个对象。

I'm not sure if this is the expected behavior, though this seems very off to me. 我不确定这是否是预期的行为,虽然这对我来说似乎很不对劲。 If anybody has any insight, I'd appreciate it. 如果有人有任何见解,我会很感激。

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

This is actually a known bug in the UIAutomation software. 这实际上是UIAutomation软件中的已知错误。 The workaround that I've come up with is to test based on all the available properties of an element. 我提出的解决方法是基于元素的所有可用属性进行测试。 It's a real pain in the butt. 这是一个真正的痛苦的屁股。

 var el1 = ELEMENT_1;

 var el1x = el1.rect().origin.x;
 var el1y = el1.rect().origin.y;
 var el1w = el1.rect().size.width;
 var el1h = el1.rect().size.height;
 var el1n = el1.name();

 var el2 = ELEMENT_2;

 var el2x = el2.rect().origin.x;
 var el2y = el2.rect().origin.y;
 var el2w = el2.rect().size.width;
 var el2h = el2.rect().size.height;
 var el2n = el2.name();

 if(el1x == el2x && el1y == el2y &&
      el1w == el2w && el1h == el2h &&
      el1n == el2n)
 {
      // Elements are equal
      return true;
 }

take a look at tuneup.js ( http://www.tuneupjs.org/ ). 看看tuneup.js( http://www.tuneupjs.org/ )。 This library makes iOS UIAutomation a lot more pleasant. 这个库使iOS UIAutomation更加愉快。 One thing it does is extend the functionality of UIAElements, using tuneup the above line in your code would be 它做的一件事是扩展UIAElements的功能,使用你的代码中的上一行调整

var equals = (el1.equals(el2));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase如何检查快照的子代本身是否为Datasnapshot类型 - Firebase how to check if snapshot's children are of type Datasnapshot themselves 为什么 Flutter 的 CupertinoNavigationBar 与 CupertinoPageScaffold 中的孩子重叠? - Why Flutter's CupertinoNavigationBar overlaps children in CupertinoPageScaffold? UIScrollView及其子级:为什么将它们放在彼此的顶部? (自动版式) - UIScrollView and it's children: why are they placed on top of each other? (AutoLayout) 在XCode中,为什么自定义视图的子级位于自定义视图下? - In XCode, why are my custom view's children under the custom view? NSPredicate以获得孩子的孩子 - NSPredicate to get children's children's 使用它的子项调整SKSpriteNode的大小 - Resizing SKSpriteNode with it's children 空的NSArray是否相等? - Empty NSArray's are equal? UIAutomation如何确定是否UIAElement.isVisible() - How does UIAutomation determine whether a UIAElement.isVisible() iOS UIAutomation UIAElement.isVisible() 抛出过时的响应? - iOS UIAutomation UIAElement.isVisible() throwing stale response? 我希望两个按钮具有相等的宽度,并使用自动布局在屏幕上方从所有屏幕尺寸开始按比例放置自己? - I want two buttons to have equal width and position themselves proportionally in all screens sizes from the top of the scree using autolayout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM