Select 2 1
Select 2 1
Selenium
Following is a step by step process on how to select
value from dropdown in Selenium:
Before handling dropdown in Selenium and controlling
drop-down boxes, we must do following two things:
1. Import the
package org.openqa.selenium.support.ui.Selec
t
2. Instantiate the drop-down box as an object, Select
in Selenium WebDriver
As an example, go to Mercury Tours’ Registration
page (https://demo.guru99.com/test/newtours/
register.php) and notice the “Country” drop-down box
there.
drpCountry.selectByValue("234");
#4) isMultiple()
• Returns TRUE if the drop-down element allows
multiple selections at a time; FALSE if otherwise.
• Parameter: Not needed
Example
if (drpCountry.isMultiple())
{
//do something here
}
#5) deselectAll()
fi
• Clears all selected entries. This is only valid when
the drop-down element supports multiple
selections.
• Parameter: Not needed
Example:
drpCountry.deselectAll();
The code below will select the rst two options using
the selectByVisibleText() method.
fi
Command Description
selectByVisibleTe
selects/deselects an option by its
xt()/
displayed text
deselectByVisible
selectByValue()/
selects/deselects an option by
the value of its “value” attribute
deselectByValue()
selectByIndex()/
selects/deselects an option by its
index
deselectByIndex()
returns TRUE if the drop-down
isMultiple()
element allows multiple selection
at a time; FALSE if otherwise
deselectAll() deselects all previously selected
options