iOS UI自动化停用EAppForduration失败

iOS UI自动化停用EAppForduration失败,ios,ios-ui-automation,Ios,Ios Ui Automation,我正在编写第一个UI自动化脚本,但在下面的deactivateAppForDuration行遇到了一个失败: // Verify password field is shown when app is moved to the foreground UIALogger.logMessage("move app to background"); target.deactivateAppForDuration(10); UIALogger.logMessage("move app to foregr

我正在编写第一个UI自动化脚本,但在下面的deactivateAppForDuration行遇到了一个失败:

// Verify password field is shown when app is moved to the foreground
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(10);
UIALogger.logMessage("move app to foreground");
我从仪器中得到的错误是:

脚本引发未捕获的JavaScript错误:无法对无效元素执行操作:UIAElementNil from target.frontMostApp().switcherScrollView().buttons()[“TimeClock”]

我在测试设备上看到的是,应用程序已切换到后台,iOS应用程序切换器正在显示。我可以看到我的应用程序(时钟)。从错误消息和设备屏幕上都可以看出,UI Automation无法选择我的应用程序以过渡到前台

还有其他人遇到过这个问题吗?附近有工作吗


谢谢。

我已经试过你的代码,在这里效果很好。如果在一个新的Instruments文件中运行以下代码(除此之外什么都不运行),这是否有效

var target = UIATarget.localTarget();
UIALogger.logMessage("move app to background");
target.deactivateAppForDuration(1);
UIALogger.logMessage("move app to foreground");
请注意:仪器并不总是准确地显示错误发生的位置。有时,它在显示的线的上方或下方有几行。 但是:错误发生的原因是正确的。我承认你在这一行有一个错误,我猜你从跳板回来后会打电话:

Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]

你确定你的应用程序中存在可以访问的元素
switcherScrollView().buttons()[“TimeClock”]
。重新启动我的设备为我解决了这个问题。

在这种情况下,
switcherScrollView()
表示设备本身而不是应用程序中的切换器控件
switcherScrollView().buttons()[“TimeClock”]
表示应用程序切换器中他的应用程序的图标。在这种情况下,重新启动模拟器,但这对我也有效。