Counting the number of elements
<p>I need to count the number of elements which in this case the number of products held by each customer. My attempt for solving this is by counting the number of "li" tag, then accessing "ticket-type". Any suggestion on how this can be achieved?: </p>

<pre><code>List&lt;WebElement&gt; labels = driver.findElements(By.xpath("//label[@class='ticket-type']"));
int ProdNum = labels.size();
String strI1 = Integer.toString(ProdNum);
System.out.print("Number of products on this card:" + strI1);
// getting the name of the last product
String LastProd = labels.get(labels.size() - 1).getText();
System.out.print("The last ordered product was:" + LastProd);
</code></pre>

<p>The .html code for this is shown below, where there are 5 products I need to count.</p>

<pre><code>&lt;div class="card-details row"&gt;
  &lt;div class="pane base4"&gt;
  &lt;div class="pane base4"&gt;
    &lt;div class="vertical-accordion"&gt;
       &lt;ul id="accordion-9" class="accordion"&gt;
          &lt;li class="open-li"&gt;
             &lt;a class="toggle-link open" href="#"&gt;
             &lt;div class="accordion-drop" style="display: block;"&gt;
                &lt;ul&gt;
                   &lt;li&gt;
                      &lt;label class="ticket-type"&gt;7 day megarider&lt;/label&gt;
                      &lt;label class="validity"&gt; (7 day: 04 July to 10 July 2016 ) &lt;/label&gt;
                   &lt;/li&gt;
                   &lt;li&gt;
                   &lt;li&gt;
                   &lt;li&gt;
                   &lt;li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
        &lt;/li&gt;
     &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>