Bird
0
0

How do you select the option at index 1 (second option) from a dropdown using Selenium Java's Select class?

easy📝 Syntax Q3 of 15
Selenium Java - Handling Form Elements
How do you select the option at index 1 (second option) from a dropdown using Selenium Java's Select class?
Aselect.selectByIndex(1);
Bselect.selectByValue(1);
Cselect.selectByVisibleText("1");
Dselect.selectByIndex(2);
Step-by-Step Solution
Solution:
  1. Step 1: Understand index-based selection

    Indexing in Select starts at 0, so index 1 is the second option.
  2. Step 2: Verify correct method and parameter

    selectByIndex(1) selects the second option; selectByValue(1) looks for value="1"; selectByVisibleText("1") looks for visible text "1"; selectByIndex(2) selects third option.
  3. Final Answer:

    select.selectByIndex(1); -> Option A
  4. Quick Check:

    Index 1 means second option [OK]
Quick Trick: Index starts at 0, so second option is index 1 [OK]
Common Mistakes:
  • Using selectByValue with an integer index
  • Confusing index with visible text
  • Using index 2 for second option

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes