我想弄清楚如何以编程方式点击网页上的按钮。如何以编程方式单击ASP.NET网页上的按钮?
具体来说,我有一个带WebBrowser控件的WinForm。一旦导航到目标ASP.NET登录页面我想要的工作,在DocumentCompleted事件处理程序,我有以下编码:
HtmlDocument doc = webBrowser1.Document;
HtmlElement userID = doc.GetElementById("userIDTextBox");
userID.InnerText = "user1";
HtmlElement password = doc.GetElementById("userPasswordTextBox");
password.InnerText = "password";
HtmlElement button = doc.GetElementById("logonButton");
button.RaiseEvent("onclick");
这填补了用户名和密码文本框罚款,但我没有任何成功获得该按钮点击;我也试过“点击”,“点击”和“点击” - 还有什么?搜索msdn当然不会给我任何线索,也不会给groups.google.com。我必须接近。或者,也许不是 - 有人告诉我应该调用页面的POST方法,但是如何完成并不是给出的建议的一部分。
BTW按钮编码:
<input type="submit" name="logonButton" value="Login" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="logonButton" tabindex="4" />
[这里的一个很好的参考用于使用web浏览器控件(.NET 2.0)与不同形式的元件相互作用(http://www.webtropy.com/articles/InternetExplorer.asp?Internet%20explorer)。 – 2008-10-03 20:34:10