How to press a button programmatically...

"Clark, Michael (OFM)" <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
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, in the DocumentCompleted event handler I have the following
set up for logging in:

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.

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" />

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.