iOS UIAutomation UIAElement.isVisible() 抛出过时的响应?
我试图在循环中使用 isVisible() 为我的 iOS UIAutomation 创建 waitForElement 类型的函数。当我尝试使用以下代码时,在弹出新屏幕时等待元素时失败。该元素显然在那里,因为如果我在点击该元素之前执行延迟(2),它就可以正常工作。其他人是如何实现这一点的,因为我不知所措......
这是我正在使用的 waitForElement 代码:
function waitForElement(element, timeout, step) {
if (step == null) {
step = 0.5;
}
if (timeout == null) {
timeout = 10;
}
var stop = timeout/step;
for (var i = 0; i < stop; i++) {
if (element.isVisible()) {
return;
}
target.delay(step);
}
element.logElement();
throw("Not visible");
}
I'm trying to use isVisible() within a loop to create a waitForElement type of a function for my iOS UIAutomation. When I try to use the following code, it fails while waiting for an element when a new screen pops up. The element is clearly there because if I do a delay(2) before tapping the element it works perfectly fine. How is everyone else accomplishing this, because I am at a loss...
Here's the waitForElement code that I am using:
function waitForElement(element, timeout, step) {
if (step == null) {
step = 0.5;
}
if (timeout == null) {
timeout = 10;
}
var stop = timeout/step;
for (var i = 0; i < stop; i++) {
if (element.isVisible()) {
return;
}
target.delay(step);
}
element.logElement();
throw("Not visible");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个可以使用的简单 wait_for_element 方法:
Here is a simple wait_for_element method that could be used:
我倾向于远离 wait_for_element 并寻找屏幕上的任何 ActivityIndicator 对象。我使用此方法来实际等待页面加载。
I tend to stay away from my wait_for_element and look for any activityIndicator objects on screen. I use this method to actual wait for the page to load.
这是一种使用递归的简单且更好的方法。不需要“返回 true”,但如果你想要的话。
Here is a simple and better one using recursion. "return true" is not needed but incase u want it.
解决方案
我知道这是一个老问题,但这是我针对必须针对可变定时事件执行重复任务的情况的解决方案。由于 UIAutomation 在 javascript 上运行,我使用带有空 while 循环的递归函数,在进入下一个屏幕之前检查所需的关键控制状态。这样一来,人们就不必对延迟进行硬编码。
Solution
I know this is an old question but here is my solution for a situation where I have to perform a repetitive task against a variable timed event. Since UIAutomation runs on javascript I use a recursive function with an empty while loop that checks the critical control state required before proceeding to the next screen. This way one never has to hard code a delay.