How to remove white spaces and capitalize every first letter in the string in the robotramework How to remove white spaces and capitalize every first letter in the string in the robotramework selenium selenium

How to remove white spaces and capitalize every first letter in the string in the robotramework


You were close to achieving it, but made two crucial mistakes. The first one is you used Set Variable and tried calling the python's title() string method in the argument - but that doesn't work for the keyword. It is a straightforward assignment - synonymous to the = operator; so what you ended up with as value was the string "Legal business name.title()". You should use the Evaluate keyword like in the second call, which does python's code eval.

The other mistake was to use two different variables - you store the capitalized version in the var ${temp_answer}, but then you don't remove the whitespace from it, but from the original one - ${string_1}. So even if the capitalization worked, you still wouldn't get the desired end result in the ${answer} var.

Here's a one-liner how to achieve what you need:

${answer}=    evaluate       """${string_1}""".title().replace(" ","")

The 2 methods are chained - replace() works on the result of title(), and the value of string_1 is in triple quotes so python works with its sting representation.