WebBrowser Control - How to fill a field and click a button

S

stewart

Hi,

I'm looking to automate a task using the WebBrowser Control.
Specifically I want to navigate to a given page from the internet,
populate a field then click the submit button.

Behind the scenes the submit button is actually doing javascript stuff
rather than just making a POST submission. This prevents me from just
capturing packets and making a post using the HttpWebRequest.

I'm thinking something along the line of injecting some javascript
into the HTML recieved and then using .ObjectForScripting
and .InvokeScript to use that javascript to populate the controls and
click the button.

Any takers?
 
R

Rahul Gokulnath

Hey If you still need this answered, which is unlikely cause you asked this question over a year ago.

1) Set the value on the input(text) box:

webBrowser.Document.GetElementById("input_element_id").InnerText = "input_text";

2) Get the Submit Button:
HtmlElement submitButton = dealerSiteWeb.Document.GetElementById("submit_button_id");

3) Invoke the click method on the submit button(using reflection):
Object obj = submitButton.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top