We can use the Selenium RC method getValue( ) to retrieve the value of the list option that is currently selected in the drop down field.
How to find the values of the list options in Drop Down field manually ?
Follow the below steps to find out the values of Drop Down fields list options on http://compendiumdev.co.uk/selenium/basic_html_form.html page :
1. Open http://compendiumdev.co.uk/selenium/basic_html_form.html 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 values of the list options in the Drop down field code as shown below:
So this is how we find the values of the Drop Down fields list options. Write down the value of the 'Drop Down Item 4' i.e. 'dd4' which we will be using in the coming example.
Test Description:
Now lets use getValue( ) method to retrieve the value 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-Project49' 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 'package49' under the newly created project.
5. Create a Java Class file say 'Class49' 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 'selectRetrieveAndVerify()' as shown below:
3. Use Selenium RC command select for selecting the list option 'Drop Down Item 4' from the 'Dropdown' Drop Down field as shown below:
4. Use Selenium RC command getValue( ) method for retrieving the value of the selected list option from the drop down field and also use JUnit method assertEquals( ) to verify whether the value of the selected list item is equal to the retrieved value of the list option as shown below:
5. Start the Selenium Standalone Server
6. Save and Run the 'Class49.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has passed to confirm that the value of the list item selected using select command is equal to the value of the list item retrieved using getValue( ) 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 isSomethingSelected command with drop down field will be explained in the next post.
No comments:
Post a Comment