138. Using getSelectedIndex command with drop down field






getSelectedIndex Selenium RC command is used to retrieve the index of the list option that is currently selected in the drop down field. 

How to find the index of the list options in Drop Down field manually ?

Follow the below steps to find out the ids of Drop Down fields list options on http://omayo.blogspot.in/ page :

1. Open http://omayo.blogspot.in/  page
2. Click on the drop down field to view the list options in it as shown below:


3. Index value starts with 0. So the first item in the list will have the index as 0 and the next value will be having index as 1 and so on as shown below:


So the index of the drop down item 'doc 4' in the above shown drop down field is 4. Remember this as we will be using this index in the below steps.

Test Description:

Now lets use getSelectedIndex( ) method to retrieve the index of the selected list option as explained in the below screenshot




Lets Implement the Test on Eclipse IDE:

Pre-requisites:

1. Create a new Project say 'RC-Project54' in Eclipse IDE
2. Configure the Project to work with Selenium RC
3. Configure the Selenium Standalone Server to run from Eclipse IDE
4. Create a package say 'package54' under the newly created project.
5. Create a Java Class file say 'Class54' 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 'selectRetrieveIndexAndVerify()' as shown below:



3. Use Selenium RC  command select for selecting the list option 'doc 4' from the Drop Down field as shown below:



4. Use Selenium RC  command getSelectedIndex( ) method for retrieving the index of the selected list option from the drop down field and also use JUnit method assertEquals( ) to verify whether the index of the selected list item is equal to the retrieved index of the list option as shown below:



5. Start the Selenium Standalone Server
6. Save and Run the 'Class54.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has passed to confirm that the index of the list item selected using select command is equal to the index of the list item retrieved using getSelectedIndex( ) method as shown in the below video:

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 getSelectedLabel command with drop down field  will be explained in the next post.


 

No comments:

Post a Comment

Followers

Labels