【发布时间】:2016-04-20 11:19:22
【问题描述】:
我想从列表框中选择所有值。
我尝试了下面的代码,但不幸的是它没有选择列表框中的最后一个值。
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();
列表框控件:-
<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>
输出:-
我不确定为什么它没有从列表框中选择最后一个值。谁能帮帮我。
【问题讨论】: