UIAutomation 中的 UIAlert 处理

发布于 2024-12-29 04:27:04 字数 751 浏览 3 评论 0原文

我正在尝试测试应用程序中 UIAlertview 的存在。

文档 我添加了脚本开头的以下处理程序。

UIATarget.onAlert = function onAlert(alert) {

    var title = alert.name();



    // add a warning to the log for each alert encountered

    UIALogger.logWarning("Alert with title '" + title + "' encountered!");

    UIATarget.localTarget().captureScreenWithName("alert_" + (new Date()).UTC());



    // test if your script should handle the alert, and if so, return true



    // otherwise, return false to use the default handler

    return false;

}

但是当警报弹出时,这个处理程序并没有被调用。有人可以帮我解决这个问题吗?

I am trying to test the presence of UIAlertview in app.

From the documentation i have added the following handler in the starting of the script.

UIATarget.onAlert = function onAlert(alert) {

    var title = alert.name();



    // add a warning to the log for each alert encountered

    UIALogger.logWarning("Alert with title '" + title + "' encountered!");

    UIATarget.localTarget().captureScreenWithName("alert_" + (new Date()).UTC());



    // test if your script should handle the alert, and if so, return true



    // otherwise, return false to use the default handler

    return false;

}

But this handler is not being called when the alert pop ups. Can any one help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻想少年梦 2025-01-05 04:27:04

如果警报很快弹出,则可能会发生这种情况。 来访问其标题。

UIATarget.localTarget().frontMostApp().alert().scrollViews()[0].staticTexts()[0].value(); 

您仍然可以通过注意:在 iOS7 之前省略 scrollViews()[0]

It might happen if the alert pops up very soon. You can still access its title with

UIATarget.localTarget().frontMostApp().alert().scrollViews()[0].staticTexts()[0].value(); 

Note: leave out scrollViews()[0] prior to iOS7.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文