javascript - 什么都没做时点击了取消按钮

标签 javascript ios xcode alert ios-ui-automation

我确实阅读了那三个帖子:

  1. Handling Alert with UIAutomation

  2. UIAutomation : Cancel button on Alert view is tapped without actually doing it

  3. UIATarget.onAlert = function onAlert(alert) Issue - Script doesn't seem to go into block correctly

我知道这个问题可以解决。我尝试使用人们在帖子中提出的方法,但它对我来说并不真正有效。我想在这里再问一下...

所以我需要在警报窗口中输入密码。像这样:

target.frontMostApp().keyboard().typeString("1234");

我想知道是否应该先写onAlert函数,并将这行代码放在onAlert函数后面?还是先写onAlert函数,然后把这行代码放到onAlert函数里面?

我试着做这样的事情:

 UIATarget.onAlert = function onAlert(alert)

 {

   return true;

   target.frontMostApp().keyboard().typeString("1234");

}

但它不起作用...取消按钮仍在被点击...谢谢!

最佳答案

我看到两个问题。首先,永远不会执行 typeString 行,因为它在函数中的 return 行之后。

function myExampleFunc() {
{
   doSomething(); // executes
   return true;   // exits from the function
   doAnything();  // never executed.  ever.
}

第二件事是,您似乎正在 try catch 由您自己的应用程序生成的警报:

target.frontMostApp().keyboard().typeString("1234");

您不使用 onAlert 来捕获这些; onAlert 用于处理权限弹出窗口等 iOS 警报。

关于javascript - 什么都没做时点击了取消按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33003947/

相关文章:

cocoa - Xcode : textfield redirects to nib

iphone - 动态 NumberOfRowsInSection

javascript - 将循环小数转换为分数

Javascript 如何使用纯二进制数据创建和使用 blob

ios - 如何将 JSON 数据从 viewController 传递到 UIView 以用于标签

ios - 滑动以编辑详细信息 Swift 和 Parse

ios - 为什么我的分布式应用程序看起来与在 xcode 中调试时不同?

ios - 无法修复 Xcode 上的签名身份问题

javascript - 如何在 Node.js 中遍历 JSON 数组?

javascript - 随机位置的文本淡入/淡出