0
0
Selenium Javatesting~5 mins

Select by value, visible text, index in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AselectByValue
BselectByAttribute
CselectByIndex
DselectByVisibleText
If you want to select the third option in a dropdown, which method do you use?
AselectByIndex(2)
BselectByVisibleText("3")
CselectByValue("3")
DselectByIndex(3)
What does selectByValue("banana") do?
ASelects option with visible text 'banana'
BThrows an error
CSelects option with value attribute 'banana'
DSelects option at index 'banana'
Which method is best if the visible text might change but the value attribute stays the same?
AselectByValue
BselectByIndex
CselectByVisibleText
DselectByText
What happens if you use selectByIndex with an index out of range?
ASelects the first option
BThrows an exception
CSelects the last option
DDoes nothing
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.