I want to select all the values from the listbox.
I tried the below code, But unfortunately it is not selecting the last value in the listbox.
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:1479/WebPage.aspx");
IWebElement dropdownElement = driver.FindElement(By.Id("ListBox1"));
List<IWebElement> elements = dropdownElement.FindElements(By.TagName("option")).ToList();
int totalElementCount = elements.Count - 1;
Actions act = new Actions(driver);
act.ClickAndHold(elements[0]).Perform();
act.MoveToElement(elements[totalElementCount]).Release().Perform();
ListBox Control:-
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
<asp:ListItem>Item3</asp:ListItem>
<asp:ListItem>Item4</asp:ListItem>
<asp:ListItem>Item5</asp:ListItem>
<asp:ListItem>Item6</asp:ListItem>
</asp:ListBox>
Output:-
I'm not sure why it is not selecting the last value from the Listbox. Can anyone help me.