Post

1 Star2 Stars3 Stars4 Stars5 Stars

By Arun Motoori

size( ) when used with List type variable, retrieves the count of Web Elements stored in the List 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 IDE2. Configure the Project to work with Selenium WebDriver3. 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 type variable as shown below:
5. Use size( ) command with the List 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.

Source: http://seleniumtwo-by-arun.blogspot.com/2013/07/152-using-size-to-retrieve-count-of.html

Category: aafv. 152. Using size( ) to retrieve the count of list options available in the drop down field

Você também pode querer ler

Comments are off for this post.