0

I did read those three posts:

  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

and I know this issue can be fixed. I tried to use the methods which people came up with in the posts but it doesnt really work for me. I would like to ask here again...

So I need to type a password on the alert window. Like this:

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

I was wondering if I should write the onAlert function first, and put this line of code after the onAlert function? Or write the onAlert function first, and then put this line of code inside the onAlert function?

I tried to do something like this:

 UIATarget.onAlert = function onAlert(alert)

 {

   return true;

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

}

But it is not working... The cancel button is still being tapped... Thanks!

Community
  • 1
  • 1
munmunbb
  • 297
  • 9
  • 22

1 Answers1

1

I see two problems. First, the typeString line will never be executed because it comes after the return line in the function.

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

The second thing is that it looks like you're trying to catch an alert that's generated by your own application:

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

You don't use onAlert to catch these; onAlert is for handling iOS alerts like permissions popups.

Ian
  • 11,280
  • 3
  • 36
  • 58