简体   繁体   中英

How to handle alert in UI Automation using javascript?

In my application after tapping on a one button it gives and alert.There are two button on alert window: 1. Cancel 2. Ok I have tried to tap on OK by using the solution given on the forum but it dosen't work.

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 
}

Function for handling alert dosen't called.Can anyone help me on this issue? Thanks in advance.

UIATarget.onAlert = function onAlert(alert) 
{

    UIATarget.localTarget().delay(1); 

    UIALogger.logMessage("alertShown");
    target.captureScreenWithName("AlertCaptured");
    return true;
}

app.alert().buttons()["OK"].tap();

My solution to this problem was to add an one second delay after the function that handles the alert. You can not end your script with that function.

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);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM