如何点击一个ASP.NET网页上的按钮编程? [英] How to click a button on an ASP.NET web page programmatically?
问题描述
我试图找出如何点击网页上的按钮编程。
具体来说,我有一个WebBrowser控件一个WinForm。一旦导航到目标ASP.NET登录页面我想要的工作,在DocumentCompleted事件处理程序,我有以下codeD:
的HTMLDocument DOC = webBrowser1.Document;的HtmlElement用户ID = doc.GetElementById(userIDTextBox);
userID.InnerText =USER1;的HtmlElement密码= doc.GetElementById(userPasswordTextBox);
password.InnerText =密码;的HtmlElement按钮= doc.GetElementById(logonButton);
button.RaiseEvent(的onclick);
这填补了用户名和密码文本框罚款,但我没有任何成功获得该该死的按钮单击;我还试图点击,点击和的onClick - 还有什么?一个搜索当然MSDN中没有给我的线索,也没有groups.google.com。我得接近。或者,也许不会 - 有人告诉我,我应该调用页面的POST方法,但如何做到这一点并不给出的建议的一部分。
BTW的按钮是codeD:
<输入类型=提交名称=logonButtonVALUE =登录的onclick =如果(typeof运算(Page_ClientValidate)=='功能')Page_ClientValidate();语言=JavaScript的ID =logonButton的tabindex =4/>
这是如何工作的?对我的作品
的HTMLDocument DOC = webBrowser1.Document;doc.All [userIDTextBox]的setAttribute(价值,USER1);
doc.All [userPasswordTextBox]的setAttribute(价值,密码!)。
doc.All [logonButton] InvokeMember(点击);
I am trying to figure out how to click a button on a web page programmatically.
Specifically, I have a WinForm with a WebBrowser control. Once it navigates to the target ASP.NET login page I'm trying to work with, in the DocumentCompleted event handler I have the following coded:
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");
This fills the userid and password text boxes fine, but I am not having any success getting that darned button to click; I've also tried "click", "Click", and "onClick" -- what else is there?. A search of msdn of course gives me no clues, nor groups.google.com. I gotta be close. Or maybe not -- somebody told me I should call the POST method of the page, but how this is done was not part of the advice given.
BTW The button is coded:
<input type="submit" name="logonButton" value="Login" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="logonButton" tabindex="4" />
How does this work? Works for me
HtmlDocument doc = webBrowser1.Document;
doc.All["userIDTextBox"].SetAttribute("Value", "user1");
doc.All["userPasswordTextBox"].SetAttribute("Value", "Password!");
doc.All["logonButton"].InvokeMember("Click");
这篇关于如何点击一个ASP.NET网页上的按钮编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!