python selenium detect alert error si active
Question: on this [page](https://secure.ingdirect.it/login.aspx) when digit wrong data
open alert error, i need check if this alert is open, if is open need close,
im write this code bat not working :

example alert image : <http://snag.gy/8WM0q.jpg>

my actual code :

    
    
    driver = webdriver.Firefox()
    driver.get("https://secure.ingdirect.it/login.aspx")
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtCodiceCliente").clear()
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtCodiceCliente").send_keys('1234567')
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtgg").clear()
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtgg").send_keys("01")
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtmm").clear()
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtmm").send_keys("01")
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtaaaa").clear()
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_txtaaaa").send_keys("1999")
    driver.find_element_by_id("ctl00_cphContenuto_LoginContainerUC1_LoginStepCifUC1_lnbvanti").click()
    
    if self.is_element_present(By.LINK_TEXT, "chiudi"):
        driver.find_element_by_link_text("chiudi").click()
        return
    

how i can check if this alert exist, and close it ?


Answer: you can simply use following code to check whether pop-up appears or not
(close pop-up if it is opened or do nothing if there is no pop-up):

    
    
    from selenium.common.exceptions import NoSuchElementException
    try:
        driver.find_element_by_xpath('//a[@class="popuptipo1chiudi close"]').click()
    except NoSuchElementException:
        pass
    

