Post

1 Star2 Stars3 Stars4 Stars5 Stars

By Arun Motoori
getOptions( ) command when used with Drop Down field retrieves the list of all the options that are available in the Drop Down field.Test Description:Implement the below steps:1. Open http://compendiumdev.co.uk/selenium/basic_html_form.html page2. Clear the Text Area field using clear( ) command3. Retrieve all the list options in Drop Down field using getOptions( ) command4. 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( ) commandAlso look into the comments provided on the below screenshot to understand the Test Description:
Lets Implement the Test on Eclipse IDE:Pre-requisites:1. Create a new Java Project say ‘WebDriver-Project68’ in Eclipse IDE2. Configure the Project to work with Selenium WebDriver3. Create a package say ‘package68’ under the newly created project.4. Create a Java Class file say ‘Class68’ 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 ‘getOptionsDemo()’ as shown below:
3. Create a Select Class object for Drop Down field as shown below:
4. Retrieve the all the list options in the Drop Down field using getOptions( ) and assign them to List 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 ‘Class68.java’ file by selecting the ‘JUnit Test’ option and ensure that our Automation Test has retrieved all the list options in the Drop Down 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.
Using getOptions( ) to get all the options available in Multi-Selection Box field will be explained in the next post.

Source: http://seleniumtwo-by-arun.blogspot.com/2013/07/149-using-getoptions-to-get-all-options.html

Category: aafs. 149. Using getOptions( ) to get all the options available in Drop Down field

Você também pode querer ler

Comments are off for this post.