Invoke Events with the webbrowser Control  
Author Message
JeffsMSDNUserID





PostPosted: .NET Framework Networking and Communication, Invoke Events with the webbrowser Control Top

Not sure if this is the proper forum, but it looked like the closest.

I want to automate filling out a form on a web site (which I can do with the webbrowser control), what I cannot figure out is a way to submit the form (either by form.submit or the click event of the submit button). Am I missing something really obvious here, or does someone have a workable solution for this w/o using the webbrowser control

Thanks

Jeff



.NET Development10  
 
 
JeffsMSDNUserID





PostPosted: .NET Framework Networking and Communication, Invoke Events with the webbrowser Control Top

I know I can't possibly be the only person to ever to do this...

I've answered my own question not more than an hour after posting it.

You simply get the form as an HTMLElement and call InvokeMember - sorta like this:

// get the form

HtmlElement myForm = webDoc.GetElementById("myFormId"); // where webDoc is the webbrowser.Document

// submit the form

myForm.InvokeMember("Submit");

I knew it couldn't be as hard as I was making it out to be!!!!


 
 
Garry Wyder





PostPosted: .NET Framework Networking and Communication, Invoke Events with the webbrowser Control Top

I have tried the above code and all it does is take me back to a logon form

The User name is in tack but the password is blanked. It is not like an invalid password or username. I have tried that and when the page is displayed with and invalid entry then an indication of and invalid entry is displayed.

I did get it working with the focus on the login element and using SendKey, but this is not the best way to do this. Sendkey send keys to the active form, so you cannot touch the computer when running the application.

A note here is that the web form is from a Secure server, I am not sure if that makes a difference or not.



 
 
Garry Wyder





PostPosted: .NET Framework Networking and Communication, Invoke Events with the webbrowser Control Top

I changed the submit code to the following and it started working.

wbBrowser.Document.GetElementById("Form1").frm.All("cmdGo")
frm.InvokeMember("Click")

Where "Form1" is the form name and "cmdGo" was the name of the submit button.

Thanx



 
 
reckface





PostPosted: .NET Framework Networking and Communication, Invoke Events with the webbrowser Control Top

Thanks guys, this really helped. What I did in the end was to search for elements by id and then invoke their click events (Checkbox and login button).

For example:
elementsInDoc = _htmlDoc.GetElementsByTagName("input");
bool iFound1 = false;
bool i2Found = false;
bool i3Found = false;
foreach (HtmlElement anElement in elementsInDoc)
{
if (iFound1 && i2Found && i3Found)
{
break;
}
if (anElement.Id.Contains("username_text"))
{
// We have the username text box
anElement.SetAttribute("value", userName);
iFound1 = true;
}
if (anElement.Id.Contains("company_text"))
{
// We have the Company text box
anElement.SetAttribute("value", companyName);
i2Found = true;
}
if (anElement.Id.Contains("remember_checkbox"))
{
// We have the Checkbox
anElement.SetAttribute("value", userName);
anElement.InvokeMember("Click");
//This also worked
//_browser.Navigate(document.getElementById('" + anElement.Id + "').click();");
i3Found = true;
}

}