如何使用javascript处理UI自动化中的警报?
问题描述:
在我的应用程序中,点击一个按钮后,它会给出警报。警报窗口上有两个按钮:1.取消2. Ok 我试图通过使用论坛上给出的解决方案点击确定,但它启用了'工作。如何使用javascript处理UI自动化中的警报?
UIATarget.onAlert = function onAlert(alert) {
var title = alert.name();
UIALogger.logWarning("Alert with title '" + title + "' encountered!");
if (title == "Attention")
{
alert.buttons()["OK"].tap();
return true; // bypass default handler
}
return false; // use default handler
}
用于处理警报的函数叫d.t任何人都可以帮我解决这个问题? 在此先感谢。
答
UIATarget.onAlert = function onAlert(alert)
{
UIATarget.localTarget().delay(1);
UIALogger.logMessage("alertShown");
target.captureScreenWithName("AlertCaptured");
return true;
}
app.alert().buttons()["OK"].tap();
答
我对此问题的解决方案是在处理警报的函数之后添加一秒的延迟。您无法使用该功能结束脚本。
UIATarget.onAlert = function onAlert(alert) {
var title = alert.name();
UIALogger.logWarning("Alert with title '" + title + "' encountered.");
if (title == "Are you sure you want to delete this?") {
alert.buttons()["Delete"].tap();
return true; //alert handled, so bypass the default handler
}
return false;
}
target.delay(1);
请尝试提供一个解释,而不仅仅是自己的代码示例。 :-) – 2013-02-22 11:38:18