I have a requirement where I am trying to automate the registration form which is in French language, while automating I am trying to get the text of the error messages which are in French(localised) language.

Example code snippet:

String text=driver.getText(By.cssSelector("#first_name + label.error"));//which gets the localised error message string

When I print the text some junk characters are getting printed. Actual output which is printed:

Seulement alphabets, des chiffres et des espaces sont autoris�

Expected output: Seulement Alphabets, des chiffres et des espaces sont autorisés

I am trying to assertEquals(actualoutput,expectedoutput) which is getting failed

I am getting the expected output from the language.properties file where translated text is there(which is UTF-8 converted and loaded as properties file).

I have even tried to convert the actual output to UTF-8 with the below code

byte ptext[] = text.getBytes("ISO-8859-1");
actualMessage=new String(ptext,"UTF-8");

But still it is not working getting printed with the junk characters as mentioned above. (Seulement alphabets, des chiffres et des espaces sont autoris�) Does the getText() gets the text in UTF-8 converted?

Please let me know your thoughts on this and help me.

Thanks Sairkishna


1 Answer 1


.properties files in Java use always ISO-8859-1. You are not able to save UTF-8 characters into .properties files. You must save the characters as unicode escape characters.

In your example the value of the key must look like this:

Seulement Alphabets, des chiffres et des espaces sont autoris\u00E9s

Take a look here: http://www.fileformat.info/info/unicode/char/e9/index.htm

With this solution you do not need any convert of the character set in your Java code. Just read the content of your .properties file.

There exist also some nice Eclipse plugins to edit .properties files who automatically convert text into the right format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.