简体   繁体   English

机器人框架或Python - 如何将不可打印的字符插入文本框

[英]Robot framework or Python - how to insert non-printable characters into a textbox

I need to insert string containing some special "non-printable" ASCII characters into a textbox, but after many attempts it always inserts just ordinary string without any special chars. 我需要将包含一些特殊的“不可打印”ASCII字符的字符串插入到文本框中,但经过多次尝试后,它总是只插入普通字符串而没有任何特殊字符。 Let's talk just about "Vertical tab", which makes some troubles in tested app. 我们来谈谈“垂直标签”,这会在经过测试的应用程序中产生一些麻烦。 So I need to insert value corresponding to pythonic chr(11) into the textbox (binary ASCII code is 00001011 and unicode should be \ ). 所以我需要将对应于pythonic chr(11)值插入到文本框中(二进制ASCII码为00001011 ,unicode应为\ )。 I prepared a function returning string I need from Python, called that from Robot and tried to insert it to the textbox. 我准备了一个函数返回我需要的Python字符串,从Robot调用它并尝试将其插入到文本框中。 But it always inserts just the string without the special char. 但它总是只插入没有特殊字符的字符串。 This is the Python function: 这是Python函数:

   def do_string_not_printable_chars():
     string = 'first'+chr(11)+'last'
     return string

Then I call it from robot: 然后我从机器人那里叫它:

${string}=   do string not printable chars
log to console  ${string}
input text  ${element}  ${string}
Save Data

In console correct string CONTAINING special char is printed ( first♂last ), but in the actual textbox there is just "firstlast" without the special char. 在控制台中正确的字符串first♂last打印特殊字符( first♂last ),但在实际文本框中只有"firstlast"而没有特殊字符。 If I manually COPY the string from console and paste into the textbox, it is inserted with the special char and tested application fails :) I tried to paste it also directly as unicode value in robot: 如果我从控制台手动复制字符串并粘贴到文本框中,它会插入特殊字符并且已测试的应用程序失败:)我尝试将其直接粘贴为机器人中的unicode值:

log to console  \u000b
input text  ${element}  \u000b
Save Data

And the result is the same - in console I can see special char ♂ printed, but nothing like this is inserted in the textbox. 结果是一样的 - 在控制台中我可以看到打印的特殊字符,但是在文本框中没有插入这样的字符。 I also tried various combination of Decode Bytes to String or Encode String to Bytes but the result is again just the same...eg: 我还尝试了各种Decode Bytes to StringEncode String to Bytes组合,但结果又是一样的......例如:

${value}=  encode string to bytes  \u000b  ASCII
log to console  ${value}
input text  ${element}  ${value}
Save Data

Thanks for help! 感谢帮助!

It sounds like input text would write that string letter by letter. 听起来像input text将逐个字母地写出该字符串。 Probably \ doesn't do anything, when being typed in your GUI you are testing? 在您正在测试的GUI中键入时,可能\ 没有做任何事情?

I do not have a system to check it right now, but maybe Press Key would help. 我现在没有系统检查它,但也许Press Key会有所帮助。 Something like this: 像这样的东西:

log to console  \\11
press key  ${element}  \\11
Save Data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM