It also depends on the code. Try using the code below: Instead of .getText (), use .getAttribute ("innerHTML"), which will then return what you are looking for, including any invisible HTML
<div class="no-docs-selected"> <p class="icon-alert">Please select an doc</p> </div>
I searched βPlease select a document, but did not interrupt it .gettext (). But below worked.
.
driver.findElement (By.xpath ("// p [@ class = 'warning icon']β))) GetAttribute ("innerHTML");
source share