在我的应用程序中点击一个按钮后,它会发出警报。警报窗口上有两个按钮:1。取消2.确定 我试图通过使用论坛上给出的解决方案来点击确定,但它不起作用。
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
}
处理警报的功能没有被调用。任何人都可以帮我解决这个问题吗? 提前谢谢。
答案 0 :(得分:0)
UIATarget.onAlert = function onAlert(alert)
{
UIATarget.localTarget().delay(1);
UIALogger.logMessage("alertShown");
target.captureScreenWithName("AlertCaptured");
return true;
}
app.alert().buttons()["OK"].tap();
答案 1 :(得分:0)
我对此问题的解决方案是在处理警报的函数后添加一秒钟的延迟。您无法使用该功能结束脚本。
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);