How to verify alert's text when autoacceptalerts capability is set to true

Hi all,

I am automating one iOS application trough Appium, how can i verify text that appears in alerts if autoacceptalerts capability is set to true.

Thanks in advance,
Pankaj

You cannot as you’ve told Appium to automatically accept (and close) all of your alerts automatically.

Thanks Christopher_Graham.

In case if i don’t set autoacceptalerts capability to true, than what will be the approach to handle alerts.

Did you try waitForAppScript capabaility, where you can read the alert title and then click it ?

Assuming you’re talking about Alerts your AUT invokes then simply write some functions to handle your Alerts, no differently than you would a login dialog, or any other screen in your app.

Here’s some quick Python code:

def is_alert_present(self):
    try:
        el = self.error_or_alert_dialog
        if el.exists:
            # print "Found error or alert:", el.name_attribute
            return True
    except:
        # print "Did NOT find any error or alert"
        return False
           

# Will attempt to click OK/Yes if there's multiple button choices
def accept(self):
    try:
        alert = self.driver.switch_to.alert
        text = self.all_text
        alert.accept()
        # print "Accepted alert, text =", text
        return True
    except:
        # print "Warning: Could not accept alert, possibly alert not present"
        return False


# Will attempt to click No/Cancel if there's multiple button choices
def dismiss(self):
    try:
        alert = self.driver.switch_to.alert
        text = self.all_text
        alert.dismiss()
        # print "Dismissed alert, text =", text
        return True
    except:
        # print "Warning: Could not dismiss alert, possibly alert not present"
        return False