Esempio n. 1
0
 def href(node, href):
     if isregex(href):
         return bool(href.search(node["href"]))
     else:
         # For href element attributes, Selenium returns the full URL that would
         # be visited rather than the raw value in the source. So we use XPath.
         query = x.axis("self")[x.attr("href") == str_(href)]
         return node.has_selector("xpath", query)
Esempio n. 2
0
    def field(node, field_or_value):
        from capybara.node.element import Element

        if isinstance(field_or_value, Element):
            if field_or_value["id"] and field_or_value["id"] == node["for"]:
                return True
            else:
                return node.base in field_or_value._find_xpath(
                    "./ancestor::label[1]")
        else:
            return node["for"] == str_(field_or_value)
Esempio n. 3
0
    def xpath(self, exact=None):
        """
        Returns the XPath query for this selector.

        Args:
            exact (bool, optional): Whether to exactly match text.

        Returns:
            str: The XPath query for this selector.
        """

        exact = exact if exact is not None else self.exact

        if isinstance(self.expression, AbstractExpression):
            return to_xpath(self.expression, exact=exact)
        else:
            return str_(self.expression)
Esempio n. 4
0
def normalize_text(value):
    """
    Normalizes the given value to a string of text with extra whitespace removed.

    Byte sequences are decoded. ``None`` is converted to an empty string. Everything else
    is simply cast to a string.

    Args:
        value (Any): The data to normalize.

    Returns:
        str: The normalized text.
    """

    if value is None:
        return ""

    text = decode_bytes(value) if isbytes(value) else str_(value)

    return normalize_whitespace(text)
Esempio n. 5
0
 def xpath(locator):
     expr = x.descendant("label")
     if locator:
         expr = expr[x.string.n.is_(str_(locator))
                     | x.attr("id").equals(str_(locator))]
     return expr