[Appium 1.6.3][iOS 10.2]Unable to click element with special characters

Hello,

I use RobotFramework on python 3.5 with appiumLibrary to run tests on real device iOS 10.2.
When I use keyword “Page should contains element” with a xpath that contains special characters as é or è, it works! Message log writes
20170104 16:27:11.219 : INFO : Current page contains element ‘//XCUIElementTypeButton[@label=“Mot de passe oublié ?”]’

When I use keyword “Click element” with the same xpath, message log writes:
20170104 16:27:11.897 : FAIL : ValueError: Element locator ‘//XCUIElementTypeButton[@label=“Mot de passe oublié ?”]’ did not match any elements.
And the test console writes:
[ ERROR ] Unexpected error: UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\xe9’ in position 79: ordinal not in range(128)

I migrate from python 2.7 to python 3.5 because of the special characters, so I don’t understand why there is still error with special characters.

Can you help me, please?

Best regards

I’ve had this problem. The code I use is in Ruby so it’s completely different, but I took a look and found this exceptional instruction on how to use unicode in Python 3.5:

https://docs.python.org/release/3.0.1/howto/unicode.html

Looks like you could just ‘escape’ the accented character, like:

//XCUIElementTypeButton[@label="Mot de passe oubli\u00e9 ?"]

or there are other more programatic means on that page.

Hi wreed and thank’s for the answer!! This link is very interesting!

I had try this solution but with the same result. I think the xpath returns by iOS device is encode and not interpreted by the keyword “Click element” of robotframework-appiumLibrary. The only solution is to ignore special characters by replace it by another character like “Mot de passe oubliX ?”.

It doesn’t explain why the keyword “page should contain element” works good instead of “Click element”? Maybe the last is not implement for python 3.5?

Do you have another idea??

Well, you didn’t post your code so I’m not sure exactly how you are using the keywords, but basically when you read the data in, you need to decode as unicode. For example (in Ruby, but you get the idea):

button = (find_element :xpath, '//XCUIElementTypeButton[@label="Mot de passe oublié ?"]').decode('utf-8')

Alternatively, since you’ve found the element with “Page should contains element” (sic), couldn’t you just element.click it?

Sorry if my code is off, I’ve never used Python. You may need to play around with it some.

I’m aware this is old, but I thought I’d give an answer in case anyone else was having this trouble. RobotFramework uses Python 2.6, and simply fails to handle unicode in a variety of places. Thus, the issue here is RobotFramework.