Challenge - 5 Problems
Dropdown Select Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Java code snippet?
Consider the following Selenium Java code that selects an option from a dropdown by visible text. What will be the output if the dropdown contains options: "Red", "Green", "Blue" and the code selects "Green"?
Selenium Java
WebElement dropdown = driver.findElement(By.id("colors")); Select select = new Select(dropdown); select.selectByVisibleText("Green"); String selected = select.getFirstSelectedOption().getText(); System.out.println(selected);
Attempts:
2 left
💡 Hint
The method selectByVisibleText chooses the option matching the exact visible text.
✗ Incorrect
The Select class's selectByVisibleText method selects the option with the exact visible text. Then getFirstSelectedOption returns that option's text, which is "Green" here.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the selected dropdown option?
You want to verify that the dropdown with id "fruits" has "Apple" selected after selection. Which assertion is correct in Java with TestNG?
Selenium Java
WebElement dropdown = driver.findElement(By.id("fruits")); Select select = new Select(dropdown); select.selectByVisibleText("Apple");
Attempts:
2 left
💡 Hint
Check the selected option's visible text, not the dropdown element's text or options list.
✗ Incorrect
getFirstSelectedOption().getText() returns the visible text of the selected option. This is the correct way to assert the selected value.
❓ locator
advanced2:00remaining
Which locator is best to find a dropdown element for Select class usage?
You want to locate a dropdown for selecting a country. The dropdown has a unique id "country-select". Which locator is best practice for Selenium?
Attempts:
2 left
💡 Hint
Using unique ids is the fastest and most reliable locator.
✗ Incorrect
By.id("country-select") is the best locator because ids are unique and fast to locate elements.
🔧 Debug
advanced2:00remaining
Why does this code throw UnexpectedTagNameException?
Analyze the code below. The dropdown element is a
with options inside, not a
Selenium Java
WebElement dropdown = driver.findElement(By.id("custom-dropdown")); Select select = new Select(dropdown); select.selectByIndex(1);
Attempts:
2 left
💡 Hint
Select class expects a
✗ Incorrect
Select class constructor checks if the element is a
❓ framework
expert3:00remaining
How to design a reusable method to select dropdown options by visible text?
You want to create a reusable Java method in your Selenium framework to select any dropdown option by visible text. Which method signature and implementation is best?
Attempts:
2 left
💡 Hint
Passing WebElement is more flexible and avoids driver dependency inside method.
✗ Incorrect
Option D accepts a WebElement dropdown and visible text, making it reusable and decoupled from driver or locator details.