select option code example

Example 1: dropdown in html

<select>
  <option value="actual value 1">Display Text 1</option>
  <option value="actual value 2">Display Text 2</option>
  <option value="actual value 3">Display Text 3</option>
</select>

Example 2: html select list

<label for="cars">Choose a car:</label>

<select id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Example 3: html select option selected true

<option selected='selected' />

Example 4: Select Options

Syntax 1 : SELECT-OPTIONS <SO_NAME> FOR <TABLE-FIELD>.  "THIS PRINTS TWO INPUT FIELDS (RANGE) WITH EXTENSION TO ENTER MULTIPLE RANGES
Syntax 2 : SELECT-OPTIONS <SO_NAME> FOR <TABLE-FIELD> NO INTERVALS.   "THIS PRINTS ONE INPUT FIELD WITH EXTENSION
Syntax 3 : SELECT-OPTIONS <SO_NAME> FOR <TABLE-FIELD> NO-EXTENSION. " THIS PRINTS TWO INPUT FIELDS WITH OUT ANY EXTENSION (CAN NOT ENTER MULTIPLE RANGES)
Syntax 4 : SELECT-OPTIONS <SO_NAME> FOR <TABLE-FIELD> NO INTERVALS NO-EXTENSION .THIS PRINTS ONE INPUT FIELD WITH OUT INTERVALS AND EXTENSIONS

Example 5: select dropdown

There are 2 dropdowns
1- HTML
2- SELECT

we determine what kind of dropdown it is
 -By tagName.We inspect.If it has <select> tag, it means it is <select> dropdown. 
 -If it is HTML, we can locate and click just as any other web element.
 
 I handle Select type of dropdown by using Select class from Selenium. 
    - Methods to select from dropdown:
        - selectByVisibleText
        - selectByValue
        - selectByIndex 
        
I verify which option is selected in a dropdown?
 - If we want to get the currently selected option, 
 we use getFirstSelectedOption() method.
        -> return type: currently selected option as a web element
        
--> .getOptions();
    -> This method will return all of the options in the <select> web element.
    -> return type: List<WebElement>

Tags:

Html Example