Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select an option by its visible text.
Selenium Java
Select dropdown = new Select(driver.findElement(By.id("menu"))); dropdown.selectBy[1]("Option 1");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByValue when you want to select by the text shown.
Using selectByIndex without knowing the option position.
✗ Incorrect
The method selectByVisibleText selects an option by the text shown to the user.
2fill in blank
mediumComplete the code to select an option by its value attribute.
Selenium Java
Select dropdown = new Select(driver.findElement(By.name("choices"))); dropdown.[1]("val2");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByVisibleText when the value attribute is needed.
Using selectByIndex without knowing the option's position.
✗ Incorrect
The method selectByValue selects an option by its value attribute.
3fill in blank
hardFix the error in the code to select an option by its index.
Selenium Java
Select dropdown = new Select(driver.findElement(By.cssSelector("#list"))); dropdown.selectBy[1](2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByValue or selectByVisibleText with an integer argument.
Using a non-existent method like selectByPosition.
✗ Incorrect
The correct method to select by position is selectByIndex.
4fill in blank
hardFill both blanks to select an option by visible text and then by index.
Selenium Java
Select dropdown = new Select(driver.findElement(By.id("dropdown"))); dropdown.[1]("Choice 3"); dropdown.[2](1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up selectByValue with selectByVisibleText.
Using wrong method names like selectByName.
✗ Incorrect
First select by visible text, then select by index using the correct methods.
5fill in blank
hardFill all three blanks to select options by value, visible text, and index in order.
Selenium Java
Select dropdown = new Select(driver.findElement(By.name("options"))); dropdown.[1]("v1"); dropdown.[2]("Option 2"); dropdown.[3](0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectById which does not exist.
Mixing up the order of method calls.
✗ Incorrect
Use selectByValue for value, selectByVisibleText for text, and selectByIndex for position.