#NEWLINE# def wait_for_and_switch_to_alert( driver , timeout = settings . LARGE_TIMEOUT ) : #NEWLINE# #INDENT# '\n    Wait for a browser alert to appear, and switch to it. This should be usable\n    as a drop-in replacement for driver.switch_to.alert() when the alert box\n    may not exist yet.\n    @Params\n    driver - the webdriver object (required)\n    timeout - the time to wait for the alert in seconds\n    ' #NEWLINE# for x in range ( int ( ( timeout * 10 ) ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# alert = driver . switch_to . alert ( ) #NEWLINE# dummy_variable = alert . text #NEWLINE# return alert #NEWLINE# #UNINDENT# except NoAlertPresentException : #NEWLINE# #INDENT# time . sleep ( 0.1 ) #NEWLINE# #UNINDENT# #UNINDENT# raise Exception ( ( 'Alert was not present after %s seconds!' % timeout ) )