Submitting a form while automating IE using

If you are planning to automate IE using and you have previously used WebBrowser control as an ActiveX control you could very well be surprised. You just might feel restricted using the System.Windows.Forms.WebBrowser control compared to the ActiveX Control. The first and the biggest problem you might face is that the System.Windows.Forms.WebBrowser is very strongly type checked, which makes things like in the example below impossible to achive.
AxWebBrowser1.Document.forms(0).q.value = "foxpose"
Using the newer managed control you need to use the example given below.
WebBrowser1.Document.All("q").SetAttribute("value", "foxpose")
This took quite a lot of my time yesterday. I hope this code somehow helps someone out when they are programming the new managed control in .NET 2.0 Incase you want a more detailed example just leave a comment and I will modify the post to include a more detailed example.

Technorati Tags: , ,


Anonymous said…
Thanks so much for the info. Helped me a lot!
Anonymous said…
Your post was very helpful. However, I wasn't able to submit the form using your WebBrowser1.Document.Forms(0).InvokeMember("Submit") statement. Instead I ended up clicking the submit button as follows: WebBrowser1.Document.All("submitbtn").Click()
Unknown said…
can you please look at the scenario when using AJAX controls, using update panel? When using "Submit", it just post backs the control does not do much in the screen...
Padiyath Deepak said…
I tried to submit the form using both the way
(1.WebBrowser1.Document.Forms(0).InvokeMember("Submit") and 2.WebBrowser1.Document.All("submitbtn").Click())

I am not sure why this happen. I could retrieve the element but invokemember and click are not working. The element has the id "Submit" and it returns an object successfully. My code lokks sumthng like this

webBrowser1.Document.Forms[0].InvokeMember("Submit()"); --> The last line does not generate any result

Is thr a Solution....


Deepak Padiyath
Unknown said…
Very helpful - thanks.
for Padiyath Deepak - if it still helps, I suspect form 0 is not the form with the button you are looking to submit. Try forms[1]

Popular posts from this blog

The best mobile development platform for hobbyist programmer

Using Voicemail with Airtel Prepaid Karnataka

Airtel 16Mbps for Impatient Ones