How to check the state of element in selenium webdriver
<p>Trying the below code to get the total number of number elements in the different pages. The while condition is getting true and the loop gets executed, but after reaching the last page, the condition is not getting false. </p>

<p>I'm iterating the loop by clicking on "next" button till it is enabled and have to stop the loop execution when this condition becomes false.</p>

<p>Please advice and help me out here. Have tried isEnabled(), isDisplayed as well.</p>

<p><strong>Last Page HTML mark-up</strong></p>

<pre><code>&lt;ul class="pagination-list"&gt;
    &lt;li class="disabled"&gt;
        &lt;a&gt;
            &lt;span class="icon-next"&gt;&lt;/span&gt;
        &lt;/a&gt;    
    &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p><strong>Selenium-</strong></p>

<pre><code> while(driver.findElement(By.xpath("//li[not(contains(@class, 'disabled'))]/a/span[(contains(@class, 'icon-next'))]"))!= null)
    {
        ((JavascriptExecutor)driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
        driver.findElement(By.className("icon-next")).click();
        ActiveEnrollUserCounts = driver.findElements(By.xpath("//*[@id='usersList']/tbody/tr"));
        uTotal = uTotal + ActiveEnrollUserCounts.size();
    }
    System.out.println("Active Enrolled Users Count: " +uTotal);
</code></pre>