About Me

Page views

Powered by Blogger.

Followers

Sunday 21 June 2015



How to count the number of items in the drop down field using size() using Selenium WebDriver.



Steps:

      1.  Define Firefox Browser and open the Firefox Browser
       2.  Open the URL (Website)
       3.  Assign and Select the drop-down list element
    4.  Get all the option from drop-down list and assign into List
      5.  Count the item drop-down list and assign into integer variable


package dayOne;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Count_Item_Dropdown {
       public static void main(String[] args) {
             
              //Define the Webdriver for Browser i.e. Firefox
              WebDriver driver = new FirefoxDriver();
               
              //Open the URL (Website)
        driver.get("http://housejoy.in/");
       
        //Assign and Select the dropdown list element
        Select selectDropdown = new Select(driver.findElement(By.id("cityName")));
       
        //Get all the option from dropdown list and assign into List
        List<WebElement> listOptionDropdown = selectDropdown.getOptions();
       
        // Count the item dropdown list and assign into integer variable
        int dropdownCount = listOptionDropdown.size();
       
        //Print the total count of dropdown list using integer variable
        System.out.println("Total Number of item count in dropdown list = "  + dropdownCount);      
       
       }
}


7 comments:

  1. The Blog gave me idea to count the total number of Items in the drop box my sincere thanks for sharing this post Please Continue to share this post
    Selenium Training in Bangalore

    ReplyDelete
  2. Good Post! Thank you so much for sharing this pretty post.....

    Selenium Training In Chennai

    Java Training In Chennai


    ReplyDelete

Popular Posts

Copyright © Learn Selenium Yourself | Powered by Blogger
Design by Duan Zhiyan | Blogger Theme by NewBloggerThemes.com