Michael St Clair
Michael St Clair

Reputation: 6625

Wait until alert is not present - Selenium/Python

I found this answer https://stackoverflow.com/a/19019311/1998220 that waits until the alert is present, but I need the opposite so whoever runs the macro has time to authenticate on the proxy pop up. Is there an opposite to the below code?

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

Upvotes: 7

Views: 4031

Answers (1)

alecxe
alecxe

Reputation: 473853

You can wait for a specific URL, title, or a specific element to be present or visible, but you can also have a specific alert_is_not_present custom Expected Condition:

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

Upvotes: 11

Related Questions