日期:2014-05-18 浏览次数:20811 次
private void Test() { //selectAge 为下拉框的ID HtmlElement element = this.webBrowser.Document.All["selectAge"]; if (element != null) { //下拉框元素个数 int count = element.Children.Count; //获取当前选择的元素索引 object o = element.GetAttribute("selectedIndex"); //获取当前选择的元素的value及text if (o != null && !string.IsNullOrEmpty(o.ToString())) { int selectIndex = Convert.ToInt32(o); o = element.Children[selectIndex].GetAttribute("value"); o = element.Children[selectIndex].GetAttribute("text"); } //遍历每个元素 foreach (HtmlElement item in element.Children) { System.Diagnostics.Debug.WriteLine(string.Format("value:{0},text:{1}", item.GetAttribute("value"), item.GetAttribute("text"))); } } }