【发布时间】:2021-04-29 22:09:58
【问题描述】:
我发现这个答案https://stackoverflow.com/a/19019311/1998220 一直等到出现警报,但我需要相反的情况,这样运行宏的人就有时间在代理弹出窗口上进行身份验证。下面的代码有相反的吗?
WebDriverWait(browser, 60).until(EC.alert_is_present())
【问题讨论】:
我发现这个答案https://stackoverflow.com/a/19019311/1998220 一直等到出现警报,但我需要相反的情况,这样运行宏的人就有时间在代理弹出窗口上进行身份验证。下面的代码有相反的吗?
WebDriverWait(browser, 60).until(EC.alert_is_present())
【问题讨论】:
你可以wait for a specific URL, title, or a specific element to be present or visible,但你也可以有一个特定的alert_is_not_present自定义预期条件:
class alert_is_not_present(object):
""" Expect an alert to not to be present."""
def __call__(self, driver):
try:
alert = driver.switch_to.alert
alert.text
return False
except NoAlertPresentException:
return True
【讨论】: