def submit_the_only_form(self): """ Look for a form on the page and submit it. Asserts if more than one form exists. """ form = ElementSelector(world.browser, str('//form')) assert form, "Cannot find a form on the page." form.submit()
def submit_form_id(self, id_): """ Submit the form with given id (used to disambiguate between multiple forms). """ form = ElementSelector( world.browser, str('id("{id}")'.format(id=id_)), ) assert form, "Cannot find a form with ID '{}' on the page.".format(id_) form.submit()
def submit_form_action(self, url): """ Submit the form with the given action URL (i.e. the form that submits to ``/post/my/data``). """ form = ElementSelector( world.browser, str('//form[@action="%s"]' % url), ) assert form, \ "Cannot find a form with action '{}' on the page.".format(url) form.submit()
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 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 check_element(): """Check for the element with the given id.""" assert ElementSelector( world.browser, 'id("%s")' % element_id, filter_displayed=True, ), "Expected element with given id."
def should_see_link_text(self, link_text, link_url): """Assert a link with the provided text points to the provided URL.""" elements = ElementSelector( world.browser, str('//a[@href="%s"][./text()="%s"]' % (link_url, link_text)), filter_displayed=True, ) if not elements: raise AssertionError("Expected link not found.")
def should_see_link(self, link_url): """Assert a link with the provided URL is visible on the page.""" elements = ElementSelector( world.browser, str('//a[@href="%s"]' % link_url), filter_displayed=True, ) if not elements: raise AssertionError("Expected link not found.")
def see_form(self, url): """ Assert the existence of a HTML form that submits to the given URL. """ elements = ElementSelector( world.browser, str('//form[@action="%s"]' % url), filter_displayed=True, ) if not elements: raise AssertionError("Expected form not found.")
def should_not_see_id(self, element_id): """ Assert an element with the given ``id`` is not visible. """ elements = ElementSelector( world.browser, 'id("%s")' % element_id, filter_displayed=True, ) if elements: raise AssertionError("Expected element with given id to be absent.")
def element_contains(self, element_id, value): """ Assert provided content is contained within an element found by ``id``. """ elements = ElementSelector( world.browser, str('id("{id}")[contains(., "{value}")]'.format(id=element_id, value=value)), filter_displayed=True, ) if not elements: raise AssertionError("Expected element not found.")
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 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, )