Bird
0
0

How would you design an action method to handle a dropdown selection by visible text using Selenium's Select class?

hard📝 Application Q9 of 15
Selenium Java - Page Object Model
How would you design an action method to handle a dropdown selection by visible text using Selenium's Select class?
Apublic void selectByText(String text) { dropdown.click(); dropdown.sendKeys(text); }
Bpublic void selectByText(String text) { new Select(dropdown).selectByVisibleText(text); }
Cpublic void selectByText(String text) { driver.findElement(By.xpath(text)).click(); }
Dpublic void selectByText(String text) { dropdown.select(text); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Selenium Select usage

    Select class provides selectByVisibleText method to select dropdown options by text.
  2. Step 2: Evaluate options

    public void selectByText(String text) { new Select(dropdown).selectByVisibleText(text); } correctly creates Select object and calls selectByVisibleText. Others misuse dropdown or locator.
  3. Final Answer:

    public void selectByText(String text) { new Select(dropdown).selectByVisibleText(text); } -> Option B
  4. Quick Check:

    Select class + selectByVisibleText = public void selectByText(String text) { new Select(dropdown).selectByVisibleText(text); } [OK]
Quick Trick: Use Select class and selectByVisibleText for dropdowns [OK]
Common Mistakes:
  • Trying to sendKeys directly to dropdown
  • Using incorrect locators for options
  • Calling non-existent select method on dropdown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes