[英]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: 重申:
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); }
el1
and el2
do not appear to reference the same object. el1
和el2
似乎没有引用同一个对象。 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.