예제 #1
0
파일: html.py 프로젝트: pocams/capybara.py
    def __init__(self, source):
        if not source:
            source = "<html/>"

        parser = etree.HTMLParser(encoding="utf-8")
        tree = etree.HTML(source, parser=parser)

        for element in tree.xpath("//textarea"):
            content = inner_content(element)
            content = re.sub("\A\n", "", content)
            for child in element.getchildren():
                element.remove(child)
            element.text = content

        self.tree = tree
예제 #2
0
파일: simple.py 프로젝트: ofek/capybara.py
    def value(self):
        """ str: The value of the form element. """

        if self.tag_name == "textarea":
            return inner_content(self.native)
        elif self.tag_name == "select":
            if self["multiple"] == "multiple":
                selected_options = self._find_xpath(".//option[@selected='selected']")
                return [_get_option_value(option) for option in selected_options]
            else:
                options = (
                    self._find_xpath(".//option[@selected='selected']") +
                    self._find_xpath(".//option"))
                return _get_option_value(options[0]) if options else None
        elif self.tag_name == "input" and self["type"] in ["checkbox", "radio"]:
            return self["value"] or "on"
        else:
            return self["value"]
예제 #3
0
파일: simple.py 프로젝트: ofek/capybara.py
def _get_option_value(option):
    return option.get("value") or inner_content(option)