diff --git a/scrapy/selector/lxmlsel.py b/scrapy/selector/lxmlsel.py index 301858890..bb0a4e1ec 100644 --- a/scrapy/selector/lxmlsel.py +++ b/scrapy/selector/lxmlsel.py @@ -68,7 +68,12 @@ class XPathSelector(object_ref): return etree.tostring(self.root, method=self._tostring_method, \ encoding=unicode) except (AttributeError, TypeError): - return unicode(self.root) + if self.root is True: + return u'1' + elif self.root is False: + return u'0' + else: + return unicode(self.root) def register_namespace(self, prefix, uri): if self.namespaces is None: diff --git a/scrapy/tests/test_selector.py b/scrapy/tests/test_selector.py index 20672098f..e4197b084 100644 --- a/scrapy/tests/test_selector.py +++ b/scrapy/tests/test_selector.py @@ -63,12 +63,8 @@ class XPathSelectorTestCase(unittest.TestCase): body = "
" response = TextResponse(url="http://example.com", body=body) xs = self.hxs_cls(response) - true = xs.select("//input[@name='a']/@name='a'").extract()[0] - false = xs.select("//input[@name='a']/@name='n'").extract()[0] - - # the actual result depends on the backend used - assert true in [u'1', u'True'], true - assert false in [u'0', u'False'], false + self.assertEquals(xs.select("//input[@name='a']/@name='a'").extract(), [u'1']) + self.assertEquals(xs.select("//input[@name='a']/@name='n'").extract(), [u'0']) @libxml2debug def test_selector_xml_html(self):