How to use the selenium.webdriver.support.wait.WebDriverWait function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hoelsner / product-database / tests / __init__.py View on Github external
def login_user(browser, username, password, expected_content):
        """Handle the login dialog"""
        # perform user login with the given credentials
        WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.ID, "username")))
        page_text = browser.find_element_by_tag_name('body').text
        assert "Login" in page_text, "Should be the login dialog"

        browser.find_element_by_id("username").send_keys(username)
        browser.find_element_by_id("password").send_keys(password)
        browser.find_element_by_id("login_button").click()
        WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.ID, "navbar_loggedin")))

        # check that the user sees the expected title
        page_text = browser.find_element_by_tag_name('body').text
        assert expected_content in page_text, "login may failed"
github ppetrid / yawd-admin / yawdadmin / tests.py View on Github external
def close_modal_inline(self, prefix):
        self.selenium.find_css('#modal-wrapper-%s .modal-footer button' % prefix).click()
        WebDriverWait(self.selenium, 10).until(lambda d: not d.find_css('#modal-wrapper-%s' % prefix).is_displayed())
github 2gis / contesto / contesto / core / element.py View on Github external
def _inject_sizzle(self):
        """
        :raise: JavaScriptInjectionError
        """
        ### @todo http/https
        ### @todo static file
        script = """
            var _s = document.createElement("script");
            _s.type = "text/javascript";
            _s.src = "%s";
            var _h = document.getElementsByTagName('head')[0];
            _h.appendChild(_s);
        """ % config.sizzle["url"]
        self.parent.execute_script(script)
        wait = WebDriverWait(self, float(config.timeout["normal"]))
        try:
            wait.until(lambda el: el._is_sizzle_loaded())
        except TimeoutException:
            raise JavaScriptInjectionError("Sizzle")
github leapcode / bitmask-dev / tests / functional / features / steps / common.py View on Github external
def wait_until_element_is_invisible_by_locator(context, locator_tuple,
                                               timeout=TIMEOUT_IN_S):
    wait = WebDriverWait(context.browser, timeout)
    wait.until(EC.invisibility_of_element_located(locator_tuple))
github 2gis / contesto / contesto / core / driver.py View on Github external
def find_elements_by_sizzle(self, sizzle_selector):
        """
        :type sizzle_selector: str
        :rtype: list of ContestoWebElement
        :raise: ElementNotFound
        """
        if not self._is_sizzle_loaded():
            self._inject_sizzle()

        wait = WebDriverWait(self, float(config.timeout["normal"]))
        try:
            elements = wait.until(lambda dr: dr.execute_script(dr._make_sizzle_string(sizzle_selector)))
        except TimeoutException:
            raise ElementNotFound(sizzle_selector, "sizzle selector", driver=self)

        return elements
github audax / pypo / functional_tests / test_functional.py View on Github external
def wait_until(self, callback, timeout=10):
        from selenium.webdriver.support.wait import WebDriverWait
        WebDriverWait(self.b, timeout).until(callback)
github sametmax / Django--an-app-at-a-time / libs / django / contrib / admin / tests.py View on Github external
def wait_until(self, callback, timeout=10):
        """
        Helper function that blocks the execution of the tests until the
        specified callback returns a value that is not falsy. This function can
        be called, for example, after clicking a link or submitting a form.
        See the other public methods that call this function for more details.
        """
        from selenium.webdriver.support.wait import WebDriverWait
        WebDriverWait(self.selenium, timeout).until(callback)
github mapbender / mapbender / src / Mapbender / CoreBundle / Tests / SeleniumIdeTests / lib / wms.py View on Github external
def deletewms(wd):
    if not ("Sources" in wd.find_element_by_tag_name("html").text):
        raise Exception("verifyTextPresent failed: Sources")
    wd.find_element_by_link_text("Sources").click()
    if not (len(wd.find_elements_by_css_selector("span.iconRemove.iconBig")) != 0):
        raise Exception("verifyTextPresent failed: span.iconRemove.iconBig")
    wd.find_element_by_css_selector("span.iconRemove.iconBig").click()
    elm = wd.find_element_by_class_name('ajaxWaiting')
    if (elm.is_displayed()):
        WebDriverWait(wd, 10).until(lambda d: not check_has_class(elm, 'ajaxWaiting'))
    elm = wd.find_element_by_link_text("Delete")
    WebDriverWait(wd, 10).until(lambda d: click_often(elm))
    if not ("Your WMS has been deleted" in wd.find_element_by_class_name("flashBox").text):
        raise Exception("verifyTextPresent failed: Your WMS has been deleted")
github healeycodes / bandwidth-checker / client / bandwidthchecker.py View on Github external
def test_speed(driver):
    """
    Tests internet bandwidth via Netflix's fast.com.
        :param query: A webdriver instance of chrome
        :return: Tuple with the results (speed, units) both strings
    """
    driver.get(FAST_URL)

    # wait for test to finish i.e. when 'your speed message' is shown
    WebDriverWait(driver, 120).until(
        expected_conditions.presence_of_element_located(
            (By.CSS_SELECTOR, FAST_COMPLETE_CSS))
    )

    speed_val = driver.find_element_by_id(
        FAST_SPEED_ID).get_attribute('innerHTML')
    speed_units = driver.find_element_by_id(FAST_UNITS_ID
                                            ).get_attribute('innerHTML')
    driver.quit()
    return {"speed": speed_val, "units": speed_units, "date": time.time()}
github gabfr / work-around-the-world / dags / crawlers / angel_co.py View on Github external
def lazy_get_element(driver, css_selector, timeout=30):
    return WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, css_selector)))