Google+

427. Using size( ) to retrieve the count of list options available in the drop down field






size( ) when used with List<WebElements> type variable, retrieves the count of Web Elements stored in the List<WebElements> type variable.

In this post, lets use size( ) to count the number of list options available in a drop down field.

Test Description:

Go through the comments mentioned on the below screenshot to understand the Test Description:




Lets Implement the Test on Eclipse IDE:

Pre-requisites:

1. Create a new Java Project say 'WebDriver-Project72' in Eclipse IDE
2. Configure the Project to work with Selenium WebDriver
3. Create a package say 'package72' under the newly created project.
4. Create a Java Class file say 'Class72' under the newly created package as shown below:




Actual Steps:

1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:




2. Create a test method 'countDropDownListOptions( )'  as shown below:




3. Create Select Class object for Drop Down field as shown below:




4. Retrieve all the list options from the Drop Down field using getOptions( ) command and assign them to the List<WebElement> type variable as shown below:




5. Use size( ) command with the List<WebElement> type variable for retrieving the count of list options available in the Dropdown field and assign the retrieved count to an integer variable say 'list_options_count' as shown below:



6. Enter the value of the integer variable which holds the count of the list options available in the Dropdown field into the Username text box field as shown below:




7. Save and Run the 'Class72.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has enter the count of the list options available in the drop down field  into the Username text box field as shown below:




Watch the below video:

Click here to watch the video.

Download this Project:


Click here to download this project and import into Eclipse IDE  on your machine.






Please comment below to feedback or ask questions.

Using size( ) to retrieve the count of list options available in the Multi-Selection Box field   will be explained in the next post.


No comments: