I have an element that contains text with breaks. Using Java, how can I verify that the element's text is what I'm expecting?
I am using the below code, but it always fails. The report that gets printed shows the actual and expected text values to be the same, so I don't know why it fails.
<span id="ctl00_cphMainContent_lblWelcomeText">
Dear Tester,
<br>
<br>
Line 1
<br>
<br>
Line 2
<br>
<br>
Line 3
<br>
<br>
Line 4
and my java:
public static final String PAGETEXT = "css=ctl00_cphMainContent_lblWelcomeText";
protected void verifyText(PAGETEXT, "Dear Tester,\r\n\r\nLine 1\r\n\r\nLine 2\r\n\r\nLine 3\r\n\r\nLine 4"){
//verify that the expected text is present
String actualtext = driver.getSingleElement(PAGETEXT).getText();
Assert.assertEquals(actualtext, expectedtext);
` and `\n` or `\r\n` might not convert as you expected. – zapl Dec 18 '13 at 21:31