selenium.wait_for_condition equivalent in Python bindings for WebDriver

后端 未结 3 1793
生来不讨喜
生来不讨喜 2021-02-06 06:33

I\'m moving some tests from Selenium to the WebDriver. My problem is that I can\'t find an equivalent for selenium.wait_for_condition. Do the Python bindings have this at the mo

3条回答
  •  佛祖请我去吃肉
    2021-02-06 06:43

    Here's my version of Greg Sadetsky's answer, put into a function:

    def click_n_wait(driver, button, timeout=5):
        source = driver.page_source
        button.click()
        def compare_source(driver):
            try:
                return source != driver.page_source
            except WebDriverException:
                pass
        WebDriverWait(driver, timeout).until(compare_source)
    

    It clicks the button, waits for the DOM to change and then returns.

提交回复
热议问题