getOptions( ) command when used with Drop Down field retrieves the list of all the options that are available in the Drop Down field.
Implement the below steps:
1. Open http://compendiumdev.co.uk/selenium/basic_html_form.html page
2. Clear the Text Area field using clear( ) command
3. Retrieve all the list options in Multi-Selection Box field using getOptions( ) command
4. Extract the label texts of the retrieved list options using getText() command.
5. Enter the extracted label texts into the 'Text Area Comment' text area field using sendKeys( ) command
Also look into the comments provided on the below screenshot to understand the Test Description:
Lets Implement the Test on Eclipse IDE:
1. Create a new Java Project say 'WebDriver-Project69' in Eclipse IDE
2. Configure the Project to work with Selenium WebDriver
3. Create a package say 'package69' under the newly created project.
4. Create a Java Class file say 'Class69' under the newly created package as shown below:
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 'getOptionsDemo()' as shown below:
3. Create a Select Class object for Multi-Selection Box field as shown below:
4. Retrieve all the list options in the Multi-Selection Box field using getOptions( ) and assign them to List<WebElement> type variable as shown below:
5. Clear the Text Area field as shown below:
6. Using for loop for extracting label text of each and every retrieved list option one by one and entering the extracted label text into Text Area field for confirmation:
7. Save and Run the 'Class69.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has retrieved all the list options in the Multi-Selection Box field, extracted their label text and entered the extracted label texts into the Text Area field 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.
Entering an integer value using sendKeys( ) command will be explained in the next post.