Appium 1.1.0 + Python 2.7 + latest Python bindings + iOS7 Simulator
My app invokes a variety of UIAAlert dialogs for network errors, authentication failures, etc. Some of them appear at expected times during my testing, others can theoretically appear at any given time. Right now I'm focused on the expected alerts, such as entering invalid login credentials and wanting to validate an "Authorization Failure" dialog appears. I'm struggling with determining how to best handle these various UIAAlert dialogs.
For starters, I cannot figure out how to successfully determine if an alert is even truly present. The following code ALWAYS returns an Alert object such as <selenium.webdriver.common.alert.Alert object at 0x102801f50> even if an alert is not physically displayed.
self.driver.switch_to.alert
So if I throw it in a try / catch block in an effort to write a function that will determine if an alert is present, it's always returning True since there's always an Alert object returned even when an alert is not physically available.
def is_alert_present(self):
try:
alert = self.driver.switch_to.alert
return True
except:
return False
> Run scripts which invoke an alert, I see it on screen, Appium inspector finds it, it's in the page_source XML
> is_alert_present() returns True
> Physically dismiss the alert
> is_alert_present() still returns True
> page_source absolutely has no UIAAlert (or anything else alert related) in the XML, it physically does not exist
Am I going about this the wrong way?