element.getText() method is not working in java selenium
<pre><code>&lt;span class="label label-danger" style="font-size : 13px; font-weight : 400;"&gt;Critical&lt;/span&gt;
</code></pre>

<p>Below is the xpath which I am using: </p>

<pre><code>.//tr[@data-index='0']/td/span
</code></pre>

<p>I have a line in HTML source like above. So, I have used corresponding Xpath and used <code>getText()</code> method to get the text i.e. Critical. I am succeed in that.</p>

<p>But, I have another line in another page like this.</p>

<pre><code>&lt;div class="col-xs-12"&gt;
&lt;div id="project-update-success-information" class="panel-confirmation success" style="display: none;"&gt;
&lt;span class="fa fa-check"/&gt;
  Project Updated
&lt;/div&gt;
</code></pre>

<p>Below is the xpath which I am using:-</p>

<pre><code>.//*[@id='project-update-success-information']/span
</code></pre>

<p>I have used the corresponding Xpath and <code>getText()</code>,but unfortunately it doesn't retrieve the text for me. I doubted that there is no <code>&lt;/span&gt;</code> close tag in the second line which causes the problem. Is there any other way to get the text?</p>