On 21 Jun, 07:20, "M R" <moshe.r...@zoomix.comwrote:
i am writing an application (C#) that automates the process of loading a web
page, login into a site and then simulates the navigation of the site.
the program uses a winform with a webBrowser control that is used to load
the web page. i am able to successfully navigate the site but am having
trouble entering data into the fields. the two fields are the username and
password. i would like to automatically enter the username and password into
the fields and then click the login button,.
the question is how to i programmatically access the controls on this
page in the webBrowser control and then click on the button?
thanks for any tips and hints
MR
Try something like this:
/*Assuming the following HTML in document
*
* <form>
* <input type="text" name="username" />
* <input type="password" name="password" />
* <input type="submit" name="login" value="Log In" />
* </form>
*/
mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as
mshtml.IHTMLDocument2;
mshtml.HTMLInputElement otxtUserNameBox = (mshtml.HTMLInputElement)
doc.all.item("username", 0);
otxtUserNameBox.value = "test_uname";
mshtml.HTMLInputElement otxtPassWordBox = (mshtml.HTMLInputElement)
doc.all.item("password", 0);
otxtPassWordBox.value = "test_pword";
mshtml.HTMLInputElement btnLogin = (mshtml.HTMLInputElement)
doc.all.item("login", 0);
btnLogin.click();