Permalink
Browse files

Fixes problem with searching links by text with non ascii characters …

…in zopebrowser.
  • Loading branch information...
1 parent a9c072f commit 4c88296ccb2b1c258bbec13cdc6427e1ddac0ee8 @dryobates dryobates committed Feb 4, 2014
Showing with 20 additions and 4 deletions.
  1. +8 −4 splinter/driver/zopetestbrowser.py
  2. +12 −0 tests/test_zopetestbrowser.py
@@ -87,6 +87,10 @@ def quit(self):
pass
@property
+ def htmltree(self):
+ return lxml.html.fromstring(self.html.decode('utf-8'))
+
+ @property
def title(self):
return self._browser.title
@@ -99,13 +103,13 @@ def url(self):
return self._browser.url
def find_option_by_value(self, value):
- html = lxml.html.fromstring(self.html)
+ html = self.htmltree
element = html.xpath('//option[@value="%s"]' % value)[0]
control = self._browser.getControl(element.text)
return ElementList([ZopeTestBrowserOptionElement(control, self)], find_by="value", query=value)
def find_option_by_text(self, text):
- html = lxml.html.fromstring(self.html)
+ html = self.htmltree
element = html.xpath('//option[normalize-space(text())="%s"]' % text)[0]
control = self._browser.getControl(element.text)
return ElementList([ZopeTestBrowserOptionElement(control, self)], find_by="text", query=text)
@@ -115,7 +119,7 @@ def find_by_css(self, selector):
return self.find_by_xpath(xpath, original_find="css", original_selector=selector)
def find_by_xpath(self, xpath, original_find=None, original_selector=None):
- html = lxml.html.fromstring(self.html)
+ html = self.htmltree
elements = []
@@ -205,7 +209,7 @@ def attach_file(self, name, file_path):
control.add_file(open(file_path), content_type, filename)
def _find_links_by_xpath(self, xpath):
- html = lxml.html.fromstring(self.html)
+ html = self.htmltree
links = html.xpath(xpath)
return ElementList([ZopeTestBrowserLinkElement(link, self) for link in links], find_by="xpath", query=xpath)
@@ -108,3 +108,15 @@ def test_links_with_nested_tags_xpath(self):
len(links), 1,
'Found not exactly one link with a span with text "BAR ONE". %s' % (
map(lambda item: item.outer_html, links)))
+
+ def test_finding_all_links_by_non_ascii_text(self):
+ "should find links by non ascii text"
+ non_ascii_encodings = {
+ 'pangram_pl': u'Jeżu klątw, spłódź Finom część gry hańb!',
+ 'pangram_ja': u'天 地 星 空',
+ 'pangram_ru': u'В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!',
+ 'pangram_eo': u'Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.',
+ }
+ for key, text in non_ascii_encodings.iteritems():
+ link = self.browser.find_link_by_text(text)
+ self.assertEqual(key, link['id'])

0 comments on commit 4c88296

Please sign in to comment.