In my experience, the most reliable way is to use javascript. It works well in .Net. To check, go to the following addresses one after another in Firefox or Internet Explorer:
http://www.google.com javascript:function f(){document.forms[0]['q'].value='stackoverflow';}f(); javascript:document.forms[0].submit()
Searches for "stackoverflow" on Google. To do this in VB.Net using the webbrowser control, do the following:
WebBrowser1.Navigate("http://www.google.com") Do While WebBrowser1.IsBusy OrElse WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Threading.Thread.Sleep(1000) Application.DoEvents() Loop WebBrowser1.Navigate("javascript:function%20f(){document.forms[0]['q'].value='stackoverflow';}f();") Threading.Thread.Sleep(2000) 'wait for javascript to run WebBrowser1.Navigate("javascript:document.forms[0].submit()") Threading.Thread.Sleep(2000) 'wait for javascript to run
Notice how the space in the URL is converted to% 20. I am not sure if this is necessary, but it cannot hurt. It is important that the first javascript is in the function. Sleep () calls must wait for Google to load, as well as for javascript. Do While Loop can run forever if the page does not load, so for automation purposes there is a counter that will time out, say, after 60 seconds.
Of course, for Google you can simply go directly to www.google.com?q=stackoverflow, but if your site has hidden input fields, etc., then this is the way to go. Only works for HTML sites - flash is a completely different matter.
source share