Recall & Review
beginner
What does
selectByValue do in Selenium?It selects an option in a dropdown by matching the option's
value attribute.Click to reveal answer
beginner
How does
selectByVisibleText work?It selects an option in a dropdown by matching the exact text shown to the user.
Click to reveal answer
beginner
What is the role of
selectByIndex?It selects an option based on its position (index) in the dropdown list, starting at 0.
Click to reveal answer
intermediate
Write the Java code snippet to select an option by visible text "Apple" using Selenium.
Select dropdown = new Select(driver.findElement(By.id("fruit")));
dropdown.selectByVisibleText("Apple");
Click to reveal answer
intermediate
Why might you choose
selectByValue over selectByVisibleText?Because
value attributes are less likely to change than visible text, making tests more stable.Click to reveal answer
Which method selects an option by the text the user sees?
✗ Incorrect
selectByVisibleText matches the option's displayed text.If you want to select the third option in a dropdown, which method do you use?
✗ Incorrect
Index starts at 0, so the third option is index 2.
What does
selectByValue("banana") do?✗ Incorrect
It selects the option whose value attribute equals 'banana'.
Which method is best if the visible text might change but the value attribute stays the same?
✗ Incorrect
Selecting by value is more stable if visible text changes.
What happens if you use
selectByIndex with an index out of range?✗ Incorrect
An exception is thrown if the index is invalid.
Explain how to select an option from a dropdown using Selenium by value, visible text, and index.
Think about the different ways you can identify an option in a dropdown.
You got /3 concepts.
Describe a situation where selecting by value is better than selecting by visible text.
Consider what changes more often: what the user sees or the underlying code.
You got /3 concepts.