from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import UnexpectedAlertPresentException
# Presence of a pop approach:
EC.alert_is_present () (driver) detecting the presence of pop
try:
WebDriverWait (driver, 10) .until ( EC.title_is (u " My Portal"))
the except UnexpectedAlertPresentException: #alert process
print ( "alert processing")
the while EC.alert_is_present () (Driver): # loop detection, can cope An indefinite number of pop
Result = EC.alert_is_present () (Driver)
Print (result.text)
result.accept ()
print ( 'login failed log on again')
Login ()
the except exceptions.TimeoutException: # 20,191,215
Login () # login failed log on again
else: # by logging
print ( "log on")
# pop present processing method two:
Print ( "alert processing")
the try:
for i in the Range (2): # can cope with the possible one or two pop
alert = driver.switch_to.alert
Print (alert.text)
alert.accept () # remove the browser warning
NoAlertPresentException the except:
Pass
# '' 'pop three processing method, the sample code
the try:
WebDriverWait (Driver, 10, 0.5) .until (EC.alert_is_present ())
= driver.switch_to.alert Alert
Print (alert.text)
alert.accept () # remove the browser alerts
the except exceptions.TimeoutException:
Print ( "NO Alert")