Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created August 4, 2022 05:13
Show Gist options
  • Save bharathmuddada/092905791576ba906a01a6e0c1dd2d84 to your computer and use it in GitHub Desktop.
Save bharathmuddada/092905791576ba906a01a6e0c1dd2d84 to your computer and use it in GitHub Desktop.
Dropdown example with Selenium C#
public class DropDownSample {
public static void Main(string[] args)
{
new DriverManager().SetUpDriver(new ChromeConfig());
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/dropdown");
driver.Manage().Window.Maximize();
var dropdownelement = driver.FindElement(By.Id("dropdown"));
SelectElement se = new SelectElement(dropdownelement);
se.SelectByIndex(1);
se.SelectByText("Option 2");
se.SelectByValue("1");
var alloptions = se.Options;
foreach (var option in alloptions)
{
Console.WriteLine(option.Text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment