-1

Hey everyone I have been searching for solutions on how to find a way to allow my program to read French accents when finding an element with css selector. The inner text contains a word that has a accent (crédit) but instead it gives me an error saying that it finds cr?dit.

Clearly it cannot read the accent provided. I am using netBeans as my IDE and my project is both in English and French. all the English code works and when I switch the lang to "fr" it checks my .properties file and finds the right text by can't read the accents that I put in the French version of the. properties file.

I am using UTF-8 and I also tried using unicode in my properties file for the accented letters but that doesn't seem to work either. Does anyone Know why the program doesn't recognize accents in the WebDriver? And any Solution would be helpful.

I also added the text that many ppl suggested inside of the netbeans.config file ( -J-Dfile.encoding=UTF-8 )and also added in the pom file the 2 lines suggested on stack overflow

( <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>)

ssss
  • 1
  • Welcome to Stack Overflow. Please take the 2-minute [tour]. Moreover, open [Help] and read at least [ask]. Then, [edit] your question to provide a [mcve]. – JosefZ Jan 13 '22 at 21:10
  • 1
    When you see that "?" character displayed, it doesn't necessarily mean the character isn't read in the right encoding... just that whatever is doing the display doesn't include the extended characterset. For instance you might see that in the console which has a very simple font... even when it's getting the correct character. I think it's going to be two bits(bytes?) for UTF-8. – pcalkins Jan 13 '22 at 21:39
  • Have you tried setting up the language using `ChromeOptions`? For example: `ChromeOptions chromeOptions = new ChromeOptions();` and then `chromeOptions.addArguments("--lang=fr");`. Assuming you're reading standard French. You can look up on the web the most correct language code for the region. – hfontanez Jan 13 '22 at 22:03
  • problem solved! in the pom.xml file it was using java 8 instead of java 11 and java 11 fixes many encoding issues related to ISO8551 and converts everything more to UTF-8 – ssss Jan 17 '22 at 21:26

1 Answers1

0

First, verify that you save/serve the CSS file as UTF-8 (Maybe save with BOM can help).

If that didn't help you can save the CSS text escaped (only as ASCII).

crédit can be saved both as cr\00E9 dit or with accents acute entities cr&eacute;dit

For the bigger discussion about using Unicode in CSS: Adding HTML entities using CSS content

Zvi Azran
  • 91
  • 6
  • i am doing test automation so i am not using any css file, just selectors and pure java code. When I run the script, my test output page says that it can't find the inner text [cr?dit] which is suppose to say crédit . the english version of the project works but i have to change the language to french but selenium doesn't identify the words with the accents. – ssss Jan 14 '22 at 21:11
  • Got it, so for some reason you are not looking at it in UTF-8.. – Zvi Azran Jan 15 '22 at 04:01
  • Maybe it's just a version thing? See this - they did have bugs like this in the past: https://github.com/SeleniumHQ/selenium/issues/4462 – Zvi Azran Jan 15 '22 at 04:08