Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Select object for the dropdown element.
Selenium Java
WebElement dropdown = driver.findElement(By.id("menu")); Select select = new [1](dropdown);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name other than Select causes compilation errors.
Trying to create Select without passing a WebElement.
✗ Incorrect
The Select class is used to handle dropdowns in Selenium. You create a Select object by passing the dropdown WebElement to its constructor.
2fill in blank
mediumComplete the code to select an option by visible text from the dropdown.
Selenium Java
Select select = new Select(driver.findElement(By.id("options"))); select.[1]("Option 2");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByValue when the visible text is needed.
Using a non-existent method like chooseByText.
✗ Incorrect
To select an option by the text shown to the user, use selectByVisibleText method of the Select class.
3fill in blank
hardFix the error in the code to select an option by index.
Selenium Java
Select select = new Select(driver.findElement(By.name("dropdown"))); select.[1](2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByText which does not exist.
Using chooseByIndex which is not a Selenium method.
✗ Incorrect
The correct method to select an option by its index is selectByIndex. Other options are invalid or do not exist.
4fill in blank
hardFill both blanks to get all options from the dropdown and print their visible text.
Selenium Java
Select select = new Select(driver.findElement(By.id("list"))); List<WebElement> options = select.[1](); for(WebElement option : options) { System.out.println(option.[2]()); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using getAllOptions which does not exist.
Using getValue which returns attribute, not visible text.
✗ Incorrect
Use getOptions() to get all dropdown options and getText() to get the visible text of each option.
5fill in blank
hardFill both blanks to check if the dropdown allows multiple selections and then deselect all options.
Selenium Java
Select select = new Select(driver.findElement(By.id("multiSelect"))); boolean isMulti = select.[1](); if(isMulti) { select.[2](); System.out.println("All options deselected."); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isMultiSelect which does not exist.
Using deselectAllOptions which is invalid.
✗ Incorrect
Use isMultiple() to check if dropdown supports multiple selections and deselectAll() to clear all selections.