Esempio n. 1
0
def should_include_link_text(self, link_text, link_url):
    """
    Assert a link containing the provided text points to the provided URL.
    """
    return world.browser.find_element_by_xpath(str(
        '//a[@href="%s"][contains(., %s)]' %
        (link_url, string_literal(link_text))))
Esempio n. 2
0
def no_see_tooltip(self, tooltip):
    """
    Assert an element with the given tooltip (title) is not visible.
    """
    elem = world.browser.find_elements_by_xpath(str(
        '//*[@title=%(tooltip)s or @data-original-title=%(tooltip)s]' %
        dict(tooltip=string_literal(tooltip))))
    elem = [e for e in elem if e.is_displayed()]
    assert_false(elem)
Esempio n. 3
0
def click_on_label(self, label):
    """
    Click on the given label.

    On a correctly set up form this will highlight the appropriate field.
    """

    elem = world.browser.find_element_by_xpath(str(
        '//label[normalize-space(text())=%s]' % string_literal(label)))
    elem.click()
Esempio n. 4
0
def should_include_link_text(self, link_text, link_url):
    """
    Assert a link containing the provided text points to the provided URL.
    """

    assert_true(ElementSelector(
        world.browser,
        str('//a[@href="%s"][contains(., %s)]' %
            (link_url, string_literal(link_text))),
        filter_displayed=True,
    ))
Esempio n. 5
0
def should_include_link_text(self, link_text, link_url):
    """
    Assert a link containing the provided text points to the provided URL.
    """

    elements = ElementSelector(
        world.browser,
        str('//a[@href="%s"][contains(., %s)]' %
            (link_url, string_literal(link_text))),
        filter_displayed=True,
    )
    if not elements:
        raise AssertionError("Expected link not found.")
Esempio n. 6
0
def should_include_link_text(self, link_text, link_url):
    """
    Assert a link containing the provided text points to the provided URL.
    """

    elements = ElementSelector(
        world.browser,
        str('//a[@href="%s"][contains(., %s)]' %
            (link_url, string_literal(link_text))),
        filter_displayed=True,
    )
    if not elements:
        raise AssertionError("Expected link not found.")
Esempio n. 7
0
def click_on_label(self, label):
    """
    Click on the given label.

    On a correctly set up form this will highlight the appropriate field.
    """

    elem = ElementSelector(
        world.browser,
        str('//label[normalize-space(text())=%s]' % string_literal(label)),
        filter_displayed=True,
    )
    assert_true(elem, "Cannot find a label with text '{}'.".format(label))
    elem.click()
Esempio n. 8
0
def find_by_tooltip(browser, tooltip):
    """
    Find elements with the given tooltip.

    :param browser: ``world.browser``
    :param tooltip: Tooltip to search for

    Returns: an :class:`ElementSelector`
    """

    return ElementSelector(
        world.browser,
        str('//*[@title=%(tooltip)s or @data-original-title=%(tooltip)s]' %
            dict(tooltip=string_literal(tooltip))),
        filter_displayed=True,
    )
Esempio n. 9
0
def find_by_tooltip(browser, tooltip):
    """
    Find elements with the given tooltip.

    :param browser: ``world.browser``
    :param tooltip: Tooltip to search for

    Returns: an :class:`ElementSelector`
    """

    return ElementSelector(
        world.browser,
        str('//*[@title=%(tooltip)s or @data-original-title=%(tooltip)s]' %
            dict(tooltip=string_literal(tooltip))),
        filter_displayed=True,
    )
Esempio n. 10
0
def click_on_label(self, label):
    """
    Click on the given label.

    On a correctly set up form this will highlight the appropriate field.
    """

    elem = ElementSelector(
        world.browser,
        str('//label[normalize-space(text())=%s]' % string_literal(label)),
        filter_displayed=True,
    )
    if not elem:
        raise AssertionError(
            "Cannot find a label with text '{}'.".format(label))
    elem.click()
Esempio n. 11
0
def contains_content(browser, content):
    """
    Search for an element that contains the whole of the text we're looking
    for in it or its subelements, but whose children do NOT contain that
    text - otherwise matches <body> or <html> or other similarly useless
    things.
    """
    for elem in browser.find_elements_by_xpath(str(
            '//*[contains(normalize-space(.), {content}) '
            'and not(./*[contains(normalize-space(.), {content})])]'
            .format(content=string_literal(content)))):

        try:
            if elem.is_displayed():
                return True
        except StaleElementReferenceException:
            pass

    return False
Esempio n. 12
0
def contains_content(browser, content):
    """
    Search for an element that contains the whole of the text we're looking
    for in it or its subelements, but whose children do NOT contain that
    text - otherwise matches <body> or <html> or other similarly useless
    things.
    """
    for elem in browser.find_elements_by_xpath(
            str('//*[contains(normalize-space(.), {content}) '
                'and not(./*[contains(normalize-space(.), {content})])]'.
                format(content=string_literal(content)))):

        try:
            if elem.is_displayed():
                return True
        except StaleElementReferenceException:
            pass

    return False