2016-03-28 5 views
0

を検出し、このpage桁間違ったデータオープン・アラート・エラーが、私はこの警告が開いている場合、オープンする必要が近い場合は、チェック必要がある場合、イムは、このコードのバットが機能していない書く:Pythonのセレンに警告エラーSi活性

例警告画像:http://snag.gy/8WM0q.jpg

私の実際のコード:私はこのアラートが存在するかどうかを確認し、それを閉じることができますどのように

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 

答えて

0

あなたは、単に(何のポップアップが存在しない場合は、それを開いたり何もしていない場合はクローズポップアップ)のポップアップが表示されるかどうかを確認するには、次のコードを使用することができます。

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