开发者

alert handling in ui automation iphone app unable to cancel the option

system.logElementTree();

var target = UIATarget.localTarget(); target.onAlert = function onAlert(alert) { UIALogger.logDebug("There was an alert!");

target.onAlert.buttons()["No"].tap({x:164,y:278}); return false; even though no option is clicked systen n开发者_开发技巧ot performing any action Can anyone please help me ...


Instead of BamboOS suggestion which loops through various positions, you can try this inside your onAlert function:

alert.tapWithOptions({tapOffset:{x:0.5, y:0.6}});

This tap targets the middle of the UIAAlert (x:0.5) and 60% from top to bottom (y:0.6). This works when there is only one button. You have multiple buttons, then you have to changed the value of x. This works for me.


I just published a blog post regarding UI Automation and dealing with alerts: http://www.conduce.net/Blog.aspx?f=Automated-Test-of-iPad-Apps

Basically following alert handler worked for me:

UIATarget.onAlert = function onAlert(alert){   
   var name = alert.name();
   UIALogger.logMessage("alert "+name+" encountered");
   if(name == "errorAlert"){
       var positionX = 500;
       for(var positionY=300; positionY<600;positionY+=10){
           target.tap({x:positionX,y:positionY});
       }
       return true;
   }
   return false;
}


I would either use the "cancelButton" or "defaultButton" methods when handling alerts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜