Bird
0
0

Given the following dropdown HTML:

medium📝 query result Q13 of 15
Selenium Java - Handling Form Elements
Given the following dropdown HTML:
<select id="colors">
  <option value="r">Red</option>
  <option value="g">Green</option>
  <option value="b">Blue</option>
</select>

What will be the selected option after executing:
Select select = new Select(driver.findElement(By.id("colors")));
select.selectByValue("g");
AGreen
BNo option selected
CBlue
DRed
Step-by-Step Solution
Solution:
  1. Step 1: Identify option with value 'g'

    The option with value attribute "g" is Green.
  2. Step 2: Understand selectByValue behavior

    The method selectByValue("g") selects the option whose value attribute matches "g" exactly.
  3. Final Answer:

    Green -> Option A
  4. Quick Check:

    Select by value 'g' = Green [OK]
Quick Trick: Match the value attribute string exactly to select option [OK]
Common Mistakes:
  • Confusing value attribute with visible text
  • Using selectByVisibleText("g") instead of selectByValue
  • Assuming index 1 selects 'Green' without checking value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes