Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active September 15, 2022 08:14
Show Gist options
  • Save SarahElson/4223bb3d5f2970284a2b9850f76cf846 to your computer and use it in GitHub Desktop.
Save SarahElson/4223bb3d5f2970284a2b9850f76cf846 to your computer and use it in GitHub Desktop.
How To Select Dropdown In Selenium C#?
[Test]
[TestCase("Monday")]
[TestCase("Tuesday")]
[TestCase("Wednesday")]
[TestCase("Thursday")]
[TestCase("Friday")]
[TestCase("Saturday")]
[TestCase("Sunday")]
[Parallelizable(ParallelScope.All)]
public void ValidateDropDownSelection(string dayOfTheWeek)
{ driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
SelectElement dropDown = new SelectElement(driver.FindElement(By.Id("select-demo")));
dropDown.SelectByValue(dayOfTheWeek);
string actualText = driver.FindElement(By.CssSelector(".selected-value.text-size-14")).Text;
Assert.True(actualText.Contains(dayOfTheWeek), $"The expected day of the week {dayOfTheWeek} was not selected. The actual text was: {actualText}.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment