Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If by.xpath contains utf8 symbols and not condition get UnicodeEncodeError: 'ascii' #124

Closed
kixiro opened this issue Apr 11, 2017 · 6 comments

Comments

@kixiro
Copy link
Contributor

kixiro commented Apr 11, 2017

Checking for linux geckodriver:v0.14.0 in cache
Driver found in /home/toxa/.wdm/geckodriver/v0.14.0/geckodriver
Traceback (most recent call last):
  File "./first_step.py", line 21, in 
    s(by.xpath("//button[contains(.,'Объекты')]")).should_be(be.conditions.Clickable()).click()
  File "/usr/local/lib/python2.7/dist-packages/selene/elements.py", line 305, in should
    _wait_with_screenshot(self._webdriver, self, condition, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selene/elements.py", line 187, in _wait_with_screenshot
    return wait_for(entity, condition, timeout, polling)
  File "/usr/local/lib/python2.7/dist-packages/selene/wait.py", line 17, in wait_for
    reason_string = '{name}: {message}'.format(name=reason.__class__.__name__, message=reason_message)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 47-53: ordinal not in range(128)
@SergeyPirogov
Copy link
Contributor

Which version of python do you use?

@kixiro
Copy link
Contributor Author

kixiro commented Apr 11, 2017

python 2.7.12

@SergeyPirogov
Copy link
Contributor

SergeyPirogov commented Apr 11, 2017

try to user it like

s(by.xpath("//button[contains(.,u'Объекты')]"))

@kixiro
Copy link
Contributor Author

kixiro commented Apr 11, 2017

Object will not be found

s(by.xpath("//button[contains(.,u'Объекты')]"))

It's work:

s(by.xpath("//button[contains(.,'Объекты')]"))

but object is not found, get UnicodeEncodeError
I resolved it this way:

diff --git a/selene/wait.py b/selene/wait.py
index afc5e69..a9e9f3d 100644
--- a/selene/wait.py
+++ b/selene/wait.py
@@ -14,6 +14,8 @@ def wait_for(entity, condition, timeout=4, polling=0.1):
             reason_message = getattr(reason, 'msg',
                                      getattr(reason, 'message',
                                              getattr(reason, 'args', '')))
+            if isinstance(reason_message, unicode):
+                reason_message = reason_message.encode('unicode-escape')
             reason_string = '{name}: {message}'.format(name=reason.__class__.__name__, message=reason_message)
             screen = getattr(reason, 'screen', None)
             stacktrace = getattr(reason, 'stacktrace', None)

@SergeyPirogov
Copy link
Contributor

could you please create PR for this

@SergeyPirogov
Copy link
Contributor

#130

@yashaka yashaka closed this as completed May 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants