0
0
Selenium Javatesting~20 mins

Select class for dropdowns in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dropdown Select Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
ABlue
BRed
CGreen
DNoSuchElementException
Attempts:
2 left
💡 Hint
The method selectByVisibleText chooses the option matching the exact visible text.
assertion
intermediate
2: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");
AAssert.assertEquals(select.getFirstSelectedOption().getText(), "Apple");
BAssert.assertTrue(select.getOptions().contains("Apple"));
CAssert.assertEquals(dropdown.getText(), "Apple");
DAssert.assertFalse(select.isMultiple());
Attempts:
2 left
💡 Hint
Check the selected option's visible text, not the dropdown element's text or options list.
locator
advanced
2: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?
ABy.cssSelector("select[name='country']")
BBy.id("country-select")
CBy.xpath("//select[@name='country']")
DBy.className("dropdown")
Attempts:
2 left
💡 Hint
Using unique ids is the fastest and most reliable locator.
🔧 Debug
advanced
2:00remaining
Why does this code throw UnexpectedTagNameException?
Analyze the code below. The dropdown element is a
with options inside, not a tag, not other HTML elements.