139. Using getSelectedLabel command with drop down field






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

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

Follow the below steps to find out the labels 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. The labels are nothing  but the names that are displayed in the list as shown below:




Test Description:

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



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


 

No comments:

Post a Comment

Followers

Labels