Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用2个按钮处理iPhone警报(要单击非默认按钮)_Javascript_Iphone_Cocoa Touch_Automation - Fatal编程技术网

Javascript 如何使用2个按钮处理iPhone警报(要单击非默认按钮)

Javascript 如何使用2个按钮处理iPhone警报(要单击非默认按钮),javascript,iphone,cocoa-touch,automation,Javascript,Iphone,Cocoa Touch,Automation,我正在自动执行iPhone应用程序,同时在“收件人:”字段中键入邮件ID并单击“发送”,我会收到一个带有两个按钮“取消并发送”的确认警报。 默认按钮是“取消”。我无法点击发送按钮。下面是我使用的代码片段。请帮我做这个 //抓住把手 window = UIATarget.localTarget().frontMostApp().mainWindow(); target = UIATarget.localTarget(); app = target.frontMostApp(); button

我正在自动执行iPhone应用程序,同时在“收件人:”字段中键入邮件ID并单击“发送”,我会收到一个带有两个按钮“取消并发送”的确认警报。 默认按钮是“取消”。我无法点击发送按钮。下面是我使用的代码片段。请帮我做这个

//抓住把手

window = UIATarget.localTarget().frontMostApp().mainWindow();

target = UIATarget.localTarget();

app = target.frontMostApp();

buttons = window.buttons();

target.delay(2);
//轻触导航栏上的“发送”按钮

app.navigationBar().buttons()["Send"].tap(); 

target.delay(2);
//警报处理程序

UIATarget.onAlert = function onAlert(alert)

{
   //Unable to enter this portion of the code

   target.delay(2);

   var alerttitle = alert.name();

   UIALogger.logMessage("Alert with title: '"+alerttitle+"' encountered! ");
}
控件根本没有进入处理程序内部

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message: @"some text"
                                                           delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

[alert show];

[alert release];


- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == [alertView cancelButtonIndex])
        return;


}

使用按钮索引,您可以跟踪警报视图的哪个按钮被按下

有一项临时工作,我认为这不是最好的方法,但可以使流程继续进行

解决方案:使用按钮相对于屏幕的近似坐标点击发送按钮

我使用了以下方法来实现这一点

//Get the handles

window = UIATarget.localTarget().frontMostApp().mainWindow();

target = UIATarget.localTarget();

app = target.frontMostApp();

//Get the handle for the alert

var alertHandle = app.alert();

//Do a log Element tree for the alert to get the coordinates, height and width of the alert

alertHandle.logElementTree();

//Decide the coordinates of the point based on the value of the alert coordinates

target.tap({x:50,y:150});

@kiran-当我们打印logElementTree时,按钮显示为name或null。在您的情况下,如果您不能单击带有名称的按钮,您可以通过以数组形式引用来完成。因为屏幕上的所有元素都是以数组的形式拾取的


通常,屏幕上的按钮以数组的形式排列,从0开始,依此类推,直到按钮数。在您的情况下,您可以将发送按钮称为按钮[0]或您必须检查的任何其他索引。

默认情况下,当手动/通过仪器结束脚本时,按取消按钮。这是因为调用了默认警报处理程序,该处理程序按下默认按钮,即取消。但我想覆盖默认处理程序并单击“发送”按钮。我没有完全理解您的意思。默认情况下如何按下该按钮。您是通过代码执行的吗?不。。。我不是通过我的代码来做的。这就是我困惑的地方。在我发布的代码片段中,当我点击Send按钮后,我得到一个弹出窗口,其中有两个按钮,分别是cancel和Send按钮。按钮=窗口按钮;按钮[发送]。点击;不适合我。但是,对于不同页面中的同一应用程序,我会收到一条带有单个OK按钮的警报消息。对于该警报按钮[确定],点击;正在工作。看,试着按照我在答案中发布的方式创建警报,你想创建两个按钮警报,希望我能做到。但我不是在编写应用程序,我只是在使用javascript自动化应用程序。谢谢你的回复。是的,我同意你的看法,而且我能找到答案。其中的基础是使用UIATarget.localTarget.frontMostApp.alert.buttons[Buttonname]。点击U也可以使用UIATarget.localTarget.frontMostApp.alert.buttons[ButtonIndex]。点击I再读取一次qt,用javascript重新启动应用程序。我现在也在做同样的事情。你能帮我一下吗。停用AppForduration将从同一点重新启动。但是我想从一开始就重新启动它。你是在用仪器来实现自动化吗?如果是这样的话,很不幸没有办法重新启动它。伙计:这是苹果的限制。@kiran是的,我在用仪器。看起来你在这方面做了很多工作。你有没有尝试过暂停导入到我们在instruments中运行的脚本中的.js?当我使用这种方法时,它只是忽略了警报。如果我点击Yes或No,它只会解除警报。但被解雇后,Yes不得不做不同的任务,No不得不做不同的任务。有没有更好的方法来处理这个问题?