If I want to select an option of a dropdown box, there are several ways to do that. I always used:
driver.findElem
You can use this
(new SelectElement(driver.FindElement(By.Id(""))).SelectByText("");
public static void mulptiTransfer(WebDriver driver, By dropdownID, String text, By to)
{
String valuetext = null;
WebElement element = locateElement(driver, dropdownID, 10);
Select select = new Select(element);
List<WebElement> options = element.findElements(By.tagName("option"));
for (WebElement value: options)
{
valuetext = value.getText();
if (valuetext.equalsIgnoreCase(text))
{
try
{
select.selectByVisibleText(valuetext);
locateElement(driver, to, 5).click();
break;
}
catch (Exception e)
{
System.out.println(valuetext + "Value not found in Dropdown to Select");
}
}
}
}
You could try this:
IWebElement dropDownListBox = driver.findElement(By.Id("selection"));
SelectElement clickThis = new SelectElement(dropDownListBox);
clickThis.SelectByText("Germany");
Example for select an option from the drop down list:
Click on drop down list by using id or csspath or xpath or name. I have used id here.
driver.findElement(By.id("dropdownlistone")).click(); // To click on drop down list
driver.findElement(By.linkText("india")).click(); // To select a data from the drop down list.