try:
browser.switch_to.alert.accept()
print("show alert")
except Exception as e:
print("no alert")
下列代码可以防止反复出现alert框:
jug_flag = 0
while jug_flag != 1:
try:
browser.switch_to.alert.accept()
except Exception as e:
jug_flag = 1