Thursday, 15 May 2014

Count Number of web Elements present in web page using selenium



1) count number of Button By using Class Name

<input id="ctrl1_btnADD" class="cart" type="submit" lang="LBLAART" flag="REMOVE" value="Acart" name="lstproduct" alt="ACart" title="Add to Cart">



List<WebElement> allElements = driver1.findElements(By.className("cart"));
System.out.println(allElements.size());



2) count number of link using xpath


<a id="HOME" href="http://arunrajvdm.blogspot.com/">
<span lang="HOME">Home</span>
</a>


List<WebElement> allElements1 = driver1.findElements(By.xpath("//a"));
System.out.println(allElements1.size());

No comments:

Post a Comment