def _get_attrs_with_url(self, key_attrs, criteria, browser):
     attrs = []
     url = None
     xpath_url = None
     for attr in ['@src', '@href']:
         if attr in key_attrs:
             if url is None or xpath_url is None:
                 url = self._get_base_url(browser) + "/" + criteria
                 xpath_url = utils.escape_xpath_value(url)
             attrs.append("%s=%s" % (attr, xpath_url))
     return attrs
    def _find_by_key_attrs(self, browser, criteria, tag, constraints):
        key_attrs = self._key_attrs.get(None)
        if tag is not None:
            key_attrs = self._key_attrs.get(tag, key_attrs)

        xpath_criteria = utils.escape_xpath_value(criteria)
        xpath_tag = tag if tag is not None else '*'
        xpath_constraints = ["@%s='%s'" % (name, constraints[name]) for name in constraints]
        xpath_searchers = ["%s=%s" % (attr, xpath_criteria) for attr in key_attrs]
        xpath_searchers.extend(
            self._get_attrs_with_url(key_attrs, criteria, browser))
        xpath = "//%s[%s(%s)]" % (
            xpath_tag,
            ' and '.join(xpath_constraints) + ' and ' if len(xpath_constraints) > 0 else '',
            ' or '.join(xpath_searchers))

        return self._normalize_result(browser.find_elements_by_xpath(xpath))