0
0
Selenium Javatesting~10 mins

Select class for dropdowns in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ASelectElement
BDropdown
CWebSelect
DSelect
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name other than Select causes compilation errors.
Trying to create Select without passing a WebElement.
2fill in blank
medium

Complete 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'
AselectByVisibleText
BselectByIndex
CselectByValue
DchooseByText
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByValue when the visible text is needed.
Using a non-existent method like chooseByText.
3fill in blank
hard

Fix 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'
AselectByIndex
BchooseByIndex
CselectByValue
DselectByText
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectByText which does not exist.
Using chooseByIndex which is not a Selenium method.
4fill in blank
hard

Fill 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'
AgetOptions
BgetText
CgetValue
DgetAllOptions
Attempts:
3 left
💡 Hint
Common Mistakes
Using getAllOptions which does not exist.
Using getValue which returns attribute, not visible text.
5fill in blank
hard

Fill 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'
AisMultiple
BdeselectAll
CdeselectAllOptions
DisMultiSelect
Attempts:
3 left
💡 Hint
Common Mistakes
Using isMultiSelect which does not exist.
Using deselectAllOptions which is invalid.