为什么UIAElement的孩子不等于自己? [英] Why are UIAElement's children not equal to themselves?

查看:124
本文介绍了为什么UIAElement的孩子不等于自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到UIAutomation脚本中有一些奇怪的行为,我曾经写过一段时间我没有跑过。我的断言失败了;在做了一些挖掘后,我看到在迭代UIAElement的 .elements()时,子元素似乎与自己不等。

I noticed some weird behavior in a UIAutomation script I had written a while back that I hadn't ran in a while. 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.

这对我来说已经像过去预期的那样有效,但至少在XCode 4.3.2中被打破了

This has worked for me as expected in the past, but appears to be broken in at least XCode 4.3.2

要复制:


  1. 创建单一视图应用

  2. 在视图中抛出一些元素,在元素上设置辅助功能标签,以便它们获取UIAutomation

  3. 在UIAutomation中运行以下脚本:

  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
  3. Run the following script in 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);
}


  • 查看 el1 并且 el2 似乎没有引用同一个对象。

  • See that el1 and el2 do not appear to reference the same object.
  • 我是不确定这是否是预期的行为,虽然这对我来说似乎很不对劲。如果有人有任何见解,我会很感激。

    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.

    推荐答案

    这实际上是UIAutomation软件中的已知错误。我提出的解决方法是基于元素的所有可用属性进行测试。这是一个真正的痛苦。

    This is actually a known bug in the UIAutomation software. 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;
     }
    

    这篇关于为什么UIAElement的孩子不等于自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆