Submitting a form while automating IE using vb.net
If you are planning to automate IE using VB.net 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.
AxWebBrowser1.Document.Forms(0).submit()
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.
WebBrowser1.Document.Forms(0).InvokeMember("Submit")
Comments
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
this.webBrowser1.Document.GetElementById("username").SetAttribute("value","***");
this.webBrowser1.Document.GetElementById("password").SetAttribute("value","***");
webBrowser1.Document.Forms[0].InvokeMember("Submit()"); --> The last line does not generate any result
Is thr a Solution....
Thanks,
Deepak Padiyath
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]