自动填表的方式有很多,关键是获取控件的id或者name。
比如源代码有
| 1
 | <input id="pwdInput" tabindex="2" class="ipt-t" type="password" name="password" onMouseOver="fEvent('mouseover',this)" onFocus="fEvent('focus',this)" onBlur="fEvent('blur',this)" onMouseOut="fEvent('mouseout',this)"/>
 | 
 
那么就可以用
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
 | HtmlDocument doc = webBrowser1.Document;
foreach (HtmlElement em in doc.All) 
{
	string str = em.Id;
	if (str == "pwdInput")  
	{
		em.SetAttribute("value", "abc"); break; 
			
	}
} 
 | 
 
foreach获得了全部的控件id,然后找出 id为pwdInput的控件并赋值abc。
还可以更简单直接获取控件id,如下
| 1
2
3
4
 | HtmlElement tbUserid = webBrowser.Document.All["username"];   
HtmlElement tbPasswd = webBrowser.Document.All["password"];   
tbUserid.SetAttribute("value", "");   
tbPasswd.SetAttribute("value", "");   
 | 
 
这样就自动找到id为usename 和password的控件并赋值。
点击按钮也有很多种方式,如果知道按钮的id或者name,例如id为:“submitbutton”,直接用
| 1
2
 | HtmlElement btnSubmit = webBrowser.Document.All["submitbutton"];   
btnSubmit.InvokeMember("click");
 | 
 
如果不知道id和name,就用
| 1
 | webBrowser1.Document.Forms[0].Invoke("submit");
 | 
 
这样获取了所有该网页所有按钮连接