【问题标题】:Wait until alert is not present - Selenium/Python等到警报不存在 - Selenium/Python
【发布时间】:2021-04-29 22:09:58
【问题描述】:

我发现这个答案https://stackoverflow.com/a/19019311/1998220 一直等到出现警报,但我需要相反的情况,这样运行宏的人就有时间在代理弹出窗口上进行身份验证。下面的代码有相反的吗?

WebDriverWait(browser, 60).until(EC.alert_is_present())

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    你可以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
    

    【讨论】:

      猜你喜欢
      • 2023-01-11
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多