无法验证包含变音符号的文本 [英] Cannot verify text which contains diacritics

查看:107
本文介绍了无法验证包含变音符号的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Java的Selenium Webdriver,并尝试验证我在页面上找到的一些文本. 文本中包含ţă等之类的变音符号.

I am using selenium webdriver with java and trying to verify some texts I find on a page. The text contains diacritics like ţ ă etc.

我遇到的问题是当我使用maven从命令行运行测试时;我需要这样做,因为我会将它们集成到Jenkins中.

The problem I encounter is when I run my test from the command line using maven; I need to do this because I will be integrating them into Jenkins.

所以我在测试中有一个简单的断言:

So I have a simple assert in my test:

Assert.assertEquals("some text with ţ", driver.findElement(text).getText());

失败了,我不知道什么是使这项工作正确的方法.

which fails and I don't know what is the right way to make this work.

我已阅读到Java中字符串的默认编码为UTF-16,因此当使用getText从页面中提取文本时,该字符串已被编码,我想这意味着字符会丢失.另一方面,我不知道比较文本本身带有ţ的某些文本"是否可以正确解释.

I have read that the default encoding for strings in Java is UTF-16, so when the text is taken from the page with getText, the string is already encoded and I suppose that means that the characters are lost. On the other hand, I don't know if the comparing text itself "some text with ţ" is interpreted ok.

有人有类似的问题吗?您如何解决它们?

Has anyone had problems similar to this? And how have you solved them?

谢谢

推荐答案

Maven甚至针对您的错误发出警告:

Maven is even issuing a warning specific to your error:

WARNING: character encoding not set. Using the platform default encoding, i.e., the 
build is platform-dependent!

或类似的消息.

解决方案是:

  1. 确保将Java源代码文件保存在UTF-8中;
  2. 确保您在pom.xml(编译器插件上的设置)中显式配置了编码.

这篇关于无法验证包含变音符号的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆