137. Using getSelectedId command with drop down field






getSelectedId Selenium RC command is used to retrieve the id attribute of the list option that is currently selected in the drop down field. 

How to find the id attrribute 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. Right click on the page and select 'View Page Source' option as shown below:


3. Ensure that the HTML source code  of the page is displayed and view the code for drop down field as shown below:



4. Identify the ids of the list options in the Drop down field code as shown below:





So this is how we find the ids of the Drop Down fields list options. Write down the id of the 'doc 4'  list item i.e. 'ironman5' which we will be using in the coming example.


Test Description:

Now lets use getSelectedId( ) method to retrieve the id 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-Project53' 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 'package53' under the newly created project.
5. Create a Java Class file say 'Class53' 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 'selectRetrieveIDAndVerify()' 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 getSelectedId( ) method for retrieving the id of the selected list option from the drop down field and also use JUnit method assertEquals( ) to verify whether the id of the selected list item is equal to the retrieved id of the list option as shown below:


5. Start the Selenium Standalone Server
6. Save and Run the 'Class53.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has passed to confirm that the id of the list item selected using select command is equal to the id of the list item retrieved using getSelectedId( ) 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 getSelectedIndex command with drop down field  will be explained in the next post.


 



No comments:

Post a Comment

Followers

Labels