get text from selenium webdriver

<div class=”error”>
Error
<br/>
<input type=”hidden” value=”MESSAGE” name=”HardCheckErrorerrorMode”/>
Locn: 1341 Has 34534
<br/>
</div>

If you want to output only second line value then, there is no way to do with xpath.

So try with split the text by line

String test = driver.findElement(By.className(“error”)).getText();

System.out.println(test.split(“\n”)[1]); //this will get the second line. Locn: 1341 Has 34534

No images available.