- Oct 26, 2018
- admin
- 0
Handling Listbox in Selenium
[Test]
public void InteractWithListbox()
{
IWebDriver dr = new ChromeDriver();
dr.Navigate().GoToUrl("https://output.jsbin.com/osebed/2");
IWebElement fruitsLB = dr.FindElement(By.XPath("//select[@id='fruits']"));
SelectElement objSelect = new SelectElement(fruitsLB);
Console.WriteLine("Multi select allowed:" + objSelect.IsMultiple);
objSelect.SelectByValue("apple");
objSelect.SelectByText("Grape");
Console.WriteLine("Selected options count before:" + objSelect.AllSelectedOptions.Count);
objSelect.DeselectByText("Apple");
//objSelect.DeselectAll(); //Deselect all selected options
//objSelect.DeselectByText("Grape"); //Deselect Grape option
Console.WriteLine("Selected options count after:" + objSelect.AllSelectedOptions.Count);
}
Tags: Handling Listbox, Listbox in selenium, Selenium Tutorials
