python selenium检测警报错误si acti

2024-10-01 00:19:52 发布

您现在位置:Python中文网/ 问答频道 /正文

在此page上,当数字错误数据打开警报错误时,我需要检查此警报是否打开,如果打开需要关闭,我将编写此代码bat不工作:

示例警报图像: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

如何检查此警报是否存在并关闭它


Tags: 代码sendidbydriver错误警报element
1条回答
网友
1楼 · 发布于 2024-10-01 00:19:52

您只需使用以下代码检查弹出窗口是否出现(如果弹出窗口已打开,请关闭它;如果没有弹出窗口,则不执行任何操作):

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

相关问题 更多 >