I am a beginner to UIAutomation. I wanted to know how do I tap one of the cells in a tableView thats inside an alert. As per Apple's UI automation documentation an alert will by default tap the cancel button if you dont specifically handle the alert and return true.

I tried the below written code (found at Apple developer). But this is still tapping the cancel button.

// second alert box "Nearby listings:"
UIATarget.onAlert = function onAlert(alert) {
    var title = alert.name();
    UIALogger.logWarning("Alert with title ’" + title + "’     encountered!");
    if (title == "Nearby listings:") {
        target.frontMostApp().alert().tableViews()["Empty list"].cells()[2].tap(); //    tapping the second cell
        return true; // bypass default handler

I would highly appreciate any kind of help.

  • Are you trying to do this with an IOS app or something else?
    – Dan Snell
    Jun 20 '13 at 23:29
  • @DanSnell iOS App Jun 21 '13 at 6:08

You may want to take a look at the index position of the cell you are trying to tap.

I am guessing that:

target.frontMostApp().alert().tableViews()["Empty list"].cells()[2].tap();

The [2] is likely the index position of that element in your collection. Take a look at the position of the cell in your collection and set the index accordingly.

  • Thanks for the response. I moved my onAlert to the top (before the instance of UITarget)and that made it work. It was not even calling the onAlert function before. Jun 21 '13 at 20:01
  • Great - you can add it as an answer below with the code you changed and accepted as an answer. Good luck!
    – Dan Snell
    Jun 21 '13 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.