日期:2014-05-18  浏览次数:20957 次

如何用WebBrowers操作网页里面的同名checkBox
用WebBrowers打开的网页里有下面一些checkbox: 
<input type=checkbox name=id value="1" /> 
<input type=checkbox name=id value="2" /> 
<input type=checkbox name=id value="3" /> 
<input type=checkbox name=id value="4" /> 
我如何能在winform里操作他们是否被选? 
我现在的做法是: 
HtmlElement myId= wb.Document.All["id"]; 
myId.SetAttribute("checked", "checked"); 
这样就可以设定它点选.可是出现了多个同名ID后,我只能操作第一个,后面的却不能操作. 
请问高手们,我该用什么办法能操作到每个checkBox

------解决方案--------------------
HtmlElementCollection eles= webBrowser1.Document.GetElementsByTagName("INPUT");
HtmlElementCollection ids=eles.GetElementsByName("id");
ids[2].SetAttribute("checked", "checked"); 
  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/