首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在Selenium中断言文本,但遇到错误

尝试在Selenium中断言文本,但遇到错误
EN

Stack Overflow用户
提问于 2020-10-20 15:08:02
回答 1查看 32关注 0票数 0

你好,我正在尝试验证来自网站的文本。我也添加了下面的图片。正如您所看到的,文本上有一个BR标签。我试图断言内容,但我得到错误,即使两个文本是相同的。下面是我的代码片段

代码语言:javascript
复制
String gr1text =landingpage.getGr1().getText();
System.out.println("Pre Trim "+gr1text);
gr1text.trim().replace("\r","").replace("\n","");
System.out.println("Post Trim "+gr1text);
Assert.assertTrue(landingpage.getEb1().isDisplayed());
String gr1expected1="Geometric Reasoning";
String gr1expected2="Part I";
String expected1= gr1expected1+System.lineSeparator()+gr1expected2;
expected1.trim().replace("\r","").replace("\n","");
System.out.println("Line seperator is "+expected1);

Assert.assertEquals(gr1text,expected1);
And Here is the Console Output i Get


Pre Trim Geometric Reasoning
Part I

Post Trim Geometric Reasoning
Part I

Line seperator is Geometric Reasoning 
Part I

java.lang.AssertionError: 
expected [Geometric Reasoning 
Part I] but found [Geometric Reasoning
Part I]

You can see the text With BR Tag here

EN

回答 1

Stack Overflow用户

发布于 2020-10-20 15:48:18

问题出在您的代码中,因为这些行是无效的gr1text.trim().replace("\r","").replace("\n","");

它应该是

代码语言:javascript
复制
gr1text = gr1text.trim().replace("\r","").replace("\n","");

expected1 = expected1.trim().replace("\r","").replace("\n","");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64440137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档