2

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. 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 \u000b). I prepared a function returning string I need from Python, called that from Robot and tried to insert it to the textbox. But it always inserts just the string without the special char. This is the Python function:

   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. 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:

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...e.g.:

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

Thanks for help!

neliCZka
  • 945
  • 1
  • 16
  • 27
  • 1
    try by using the variable itself in `Input Text`, not it's value - e.g. `input text ${element} $string`; this should preserve the special symbols all the way down the selenium implementation of the command. – Todor Minakov May 16 '17 at 11:42
  • I am not sure I understand...passing the variable itself was the first option I tried `input text ${element} ${string}` and it did not work – neliCZka May 16 '17 at 11:57
  • That's a bit different - in the form `${variable}` RF will take the variable's value, and use it (as a string). On the other hand, the form `$variable` (without the curly brackets) is "telling" RF to use the variable itself. Some pseudo-python code as example - `variable = 4; print('4'); print(variable)` - the first call prints the string 4 - that's what RF would "substitute" with `${variable}`, while the second - will print the variable `variable` itself - the RF call `${a}`. – Todor Minakov May 16 '17 at 13:15
  • Look at the doc, the second part of the section - [evaluating expressions, in the Builtin lib](http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Evaluating%20expressions). Have in mind the `$variable` adds (for me) 20ms exec time on an AWS t2.medium, so don't abuse it heavily. Plus, it might not even work for your case, if py's se `send_keys` doesn't work. – Todor Minakov May 16 '17 at 13:20
  • Umm, when I used just $string it inserted directly string like this: '$string' into the field...so I am not sure how to use it.. – neliCZka May 16 '17 at 13:37
  • ... and you are right, the selenium library does not parse the variables like the builtin does, so my proposal does not work with it ¯_(ツ)_/¯. Interestingly though, I manage to send your value to an input - with `input text ${element} \u000b`, there's a symbol with non-printing icon visible in the browser, the js call in the console $0.value displays it also. This also worked - `input text ${element} man \u2642` - the char ♂ is in fact in the input – Todor Minakov May 16 '17 at 14:06
  • this second option works for me as well :) `input text ${element} man \u2642` thank you!! – neliCZka May 16 '17 at 14:25
  • hahah, well glad I accidentally helped :D – Todor Minakov May 16 '17 at 15:00

1 Answers1

0

It sounds like input text would write that string letter by letter. Probably \u000b doesn't do anything, when being typed in your GUI you are testing?

I do not have a system to check it right now, but maybe Press Key would help. Something like this:

log to console  \\11
press key  ${element}  \\11
Save Data
Noordsestern
  • 98
  • 1
  • 8
  • thanks, but `press key` does not work as well :( I also tried `send keys` from python and it did not work.. – neliCZka May 16 '17 at 11:43