Robot framework - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 49: ordinal not in range(128) while inputting text

可紊 提交于 2019-12-11 10:24:59

问题


I'm querying values from database to enter in the input field using selenium. However, for certain values I get the following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 49: ordinal not in range(128)

I'm getting the error when the value to enter in the text field is something like 'Décor'. I understand that the issue with the character "é". How can I overcome this error?

Robot code:

*** Settings ***
Library    SeleniumLibrary
Library    DatabaseLibrary

*** Test cases ***
Test
    ${value}      Get value from database
    Input text    ${locator}    ${value}

*** Keywords ***
Get value from database
    ${queryResults}    Query    ${query}
    [Return]    ${queryResults}

Note: The error specifically occurs when inputting the text into the field(Step 2). Logging the same value to the console works fine.


回答1:


This being py2 my suspect would be the actual type of the variable you use (value); it may be a bytestring with the high-ascii characters in encoded form.

Just before using it in Input Text, convert it to unicode:

${value}=    Decode Bytes To String    ${value}

If that fails - or it doesn't produce the desired result, try with Convert To String:

${value}=    Convert To String    ${value}

I suspect the latter though will preserve the "offending" characters in their encoded form, e.g. "D\xe9cor". Do let me know in the comments, I'm quite curious :)



来源:https://stackoverflow.com/questions/54800265/robot-framework-unicodedecodeerror-ascii-codec-cant-decode-byte-0xe9-in-po

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!