Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active September 15, 2022 08:15
Show Gist options
  • Save SarahElson/737445a56795860f142bdbdb0bb7451e to your computer and use it in GitHub Desktop.
Save SarahElson/737445a56795860f142bdbdb0bb7451e to your computer and use it in GitHub Desktop.
How To Select Dropdown In Selenium C#?
[Test]
public void ValidateMultipleSelection()
{
driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
string[] selectedStates = { "Florida", "New York", "Texas" };
var multiSelect = new SelectElement(driver.FindElement(By.Id("multi-select")));
Assert.IsTrue(multiSelect.IsMultiple, "The Select does not allow multiple selection.");
foreach (var state in selectedStates)
{
multiSelect.SelectByText(state);
}
multiSelect.DeselectAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment