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:
"Small", "Medium", "Large", "Extra Large"
Write the best way to select "Extra Large" using the Select class if you only know the option's value attribute is "xl" but the visible text is dynamic.
Which method should you use?
Aselect.selectByValue("xl");
Bselect.selectByVisibleText("Extra Large");
Cselect.selectByIndex(3);
Dselect.selectByPartialVisibleText("Large");
Step-by-Step Solution
Solution:
  1. Step 1: Understand selection methods

    selectByVisibleText requires exact visible text, which is dynamic here, so not reliable.
  2. Step 2: Use value attribute for stable selection

    selectByValue("xl") uses the option's value attribute, which is stable and known.
  3. Step 3: Evaluate other options

    selectByIndex(3) depends on position which may change; selectByPartialVisibleText does not exist in Select class.
  4. Final Answer:

    select.selectByValue("xl"); -> Option A
  5. Quick Check:

    Use selectByValue for stable attribute selection [OK]
Quick Trick: Use selectByValue when visible text is unreliable [OK]
Common Mistakes:
  • Using selectByVisibleText with dynamic text
  • Using invalid method selectByPartialVisibleText
  • Relying on index which may change

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes