Bird
0
0

You have a dropdown with options:

hard📝 Application Q15 of 15
Selenium Java - Handling Form Elements
You have a dropdown with options:
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Cherry</option>
<option value="4">Date</option>

You want to select "Cherry" but only know its position is third in the list. Which code snippet correctly selects "Cherry" using Selenium Java?
Aselect.selectByValue("3");
BAll of the above
Cselect.selectByVisibleText("Cherry");
Dselect.selectByIndex(2);
Step-by-Step Solution
Solution:
  1. Step 1: Understand each selection method

    selectByIndex(2) selects the third option (index starts at 0).
    selectByValue("3") selects option with value "3".
    selectByVisibleText("Cherry") selects option with visible text "Cherry".
  2. Step 2: Confirm all methods select "Cherry"

    All three methods correctly select the "Cherry" option in this dropdown.
  3. Final Answer:

    All of the above -> Option B
  4. Quick Check:

    Index, value, or text all select Cherry [OK]
Quick Trick: Any method works if you know index, value, or visible text [OK]
Common Mistakes:
  • Thinking only one method can select the option
  • Using wrong index (off by one)
  • Confusing value attribute with visible text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes