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))))
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)
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()
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, ))
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.")
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()
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, )
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()
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
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