Handling Selectbox in Selenium



Handling SelectBox In Selenium

[Test]
public void HandlingSelectBox()
{
IWebDriver dr = new ChromeDriver();
dr.Navigate().GoToUrl("https://demo.guru99.com/test/newtours/register.php");
IWebElement ddCountry = dr.FindElement(By.Name("country"));
SelectElement objSelect = new SelectElement(ddCountry);

objSelect.SelectByIndex(2);
objSelect.SelectByText("INDIA");
objSelect.SelectByValue("CHINA");
Console.WriteLine("Multiple values allowed:" + objSelect.IsMultiple);

int optCount = objSelect.Options.Count;
Console.WriteLine("options count is:" + optCount);

//objSelect.DeselectByValue("CHINA");
for (int i = 0; i < optCount; i++)
{
objSelect.SelectByIndex(i);
}
}
Tags: , , ,

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!