如何使用webdriver验证带有中断的文本

时间:2014-01-27 21:29:46

标签: java selenium

我有以下HTML,并希望验证文字。

<span id="ctl00_cphMainContent_lblWelcomeText" class="firefinder-match">
    We each spend a lot of energy on work – being here each day and often thinking about it when we’re not. So it’s to our benefit to create a work environment that is healthy and energizing … and where we can be “at our best.” When we’re at our best, we have better thinking. We’re more creative, more innovative, and it shows in our performance as individuals and collectively as an enterprise … it helps us have the best possible results. 
    <br>
    <br>
    We need your honest feedback. Be confident that your responses will be anonymous – all data goes directly to our external survey partner, Kenexa, and cannot be associated with any specific person, by me or anyone else here. The survey is the first step in the process … next we’ll work in teams to make real change happen, based on your feedback. 
    <br>
    <br>
    Thank you for taking the survey … for making the commitment. Feedback matters and we each can influence our work environment. We all share responsibility for it.
</span>

这是我正在使用的代码,但我一直都在说文本不匹配。我正在使用\ n \ n发生中断的地方。我也尝试使用\ r \ n \ r \ n发生中断的地方,但我得到了相同的结果。任何人都可以帮我确定我做错了什么吗?谢谢。

String actualtext = driver.getSingleElement("css=span#ctl00_cphMainContent_lblWelcomeText").getText();
    Assert.assertEquals(actualtext, "We each spend a lot of energy on work – being here each day and often thinking about it when we’re not. So it’s to our benefit to create a work environment that is healthy and energizing … and where we can be “at our best.” When we’re at our best, we have better thinking. We’re more creative, more innovative, and it shows in our performance as individuals and collectively as an enterprise … it helps us have the best possible results.\n\nWe need your honest feedback. Be confident that your responses will be anonymous – all data goes directly to our external survey partner, Kenexa, and cannot be associated with any specific person, by me or anyone else here. The survey is the first step in the process … next we’ll work in teams to make real change happen, based on your feedback.\n\nThank you for taking the survey … for making the commitment. Feedback matters and we each can influence our work environment. We all share responsibility for it.");

当我打印realtext时,它有休息。

  

我们每个人都在工作上花费了很多精力 - 每天都经常在这里   当我们不是时,想一想。因此,创建一个有利于我们的利益   健康,充满活力的工作环境......我们可以在哪里工作   “尽力而为。”当我们处于最佳状态时,我们会更好地思考。我们   更具创意,更具创新性,并在我们的表现中表现出来   个人和集体作为企业...它帮助我们拥有   最好的结果。

     

我们需要您的诚实反馈。相信你的回答会如此   匿名 - 所有数据直接发送给我们的外部调查合作伙伴,   Kenexa,不能与任何特定的人联系,由我或   这里的任何人。调查是这个过程的第一步......接下来   我们将团队合作,根据您的要求实现真正的变革   反馈。

     

感谢您参与调查......做出承诺。反馈   我们每个人都可以影响我们的工作环境。我们都分享   对此负责。

我不确定为什么这个问题需要-1。如果有更多信息 需要,请告诉我。我对这个比较陌生

1 个答案:

答案 0 :(得分:0)

我认为getText()只是转义了break标记,并没有将它们更改为\n。你应该做的第一件事就是打印actualtext

编辑:对不起,我错了getText()