我确实阅读了那三个帖子:
UIAutomation : Cancel button on Alert view is tapped without actually doing it
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/