所以我想点击这个按钮,如果这是你第一次点击它。将出现一个 JavaScript 警报弹出窗口。我一直在使用 firebug,只是找不到 javascript 所在的位置,我已经尝试过
if EC.alert_is_present:
driver.switch_to_alert().accept()
else:
print("no alert")
如果有警告框,上面的代码会起作用,但如果没有警告框,则会抛出错误。即使有一个 else 声明我什至尝试过
if EC.alert_is_present:
driver.switch_to_alert().accept()
elif not EC.alert_is_present:
print("no alert")
它向我抛出这个错误
selenium.common.exceptions.NoAlertPresentException: Message: No alert is present
我们如何解决这个问题?
使用 try catch 如果警报不存在则捕获NoAlertPresentException
例外:
from selenium.common.exceptions import NoAlertPresentException
try:
driver.switch_to_alert().accept()
except NoAlertPresentException as e:
print("no alert")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)