title: Getting the count of elements in a pop-up using Selenium and Java
body: <p>I am writing test cases using <code>Selenium</code> and <code>PhantomJsDriver</code> in <code>Java</code></p>
  
  <blockquote>
    <ul>
    <li><p>Selenium - 3.0.1</p></li>
    <li><p>PhantomJs - 2.1.1</p></li>
    </ul>
  </blockquote>
  
  <p><strong>Expected Scenario :</strong> 
  Open a pop-up page and find the No of elements inside the pop up page (Actually the items getting displayed inside the pop up).</p>
  
  <p>At any given point of time there can be only 3 elements inside the pop up. So i am doing an assert here.</p>
  
  <p>Below is the Code for the same</p>
  
  <ol>
  <li><p>With Class Name using <code>findElements</code> method</p>
  
  <pre><code>List&lt;WebElement&gt; foundItems = By.className("className").findElements(driver);
  
  int count = foundItems.size();
  </code></pre></li>
  <li><p>With <code>Xpath</code></p>
  
  <pre><code>int count = driver.findElements(By.xpath("//div[@class='className']")).size();
  </code></pre></li>
  </ol>
  
  <p>In both the cases i am getting the count wrong, i always get the count as multiple of elements which are inside the pop up page.</p>
  
  <p>But if i iterate over the <code>list</code> and use <code>.isDisplayed()</code> method and maintain a flag it is giving me the correct count.</p>
  
  <p>I think it might be an issue of cache or localStorage issue which <code>phantomJsDriver</code> maintains.</p>
  
  <p>How could i clear the Cache or LocalStorage using <code>Selenium</code> and <code>Java</code>.</p>
  
  <p>Or is there any other way to get it done.</p>