I am trying to write a program that simulates a simple browser search in www.google.com using the WebBrowser control. I'm really just wanting to simulate internet activity.
I came up with the idea of using a loop to send a number to the google search box and then pressing enter.
The line WebBrowser1.Document.GetElementById("q").SetAttribute("value", i) successfully sends each number in the loop to the google search box, but the next line WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click") won't initiate the google search button. I don't get any errors.
Does anyone have any ideas why WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click") doesn't work?
Also I've noticed that when I run this code and then launch Internet Explorer, the code stops. Does anyone have any ideas on this as well?
Most grateful for any help!
Regards
George
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call LoadBrowser()
End Sub
Private Sub LoadBrowser()
    WebBrowser1.Navigate("http://www.google.com/")
End Sub 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ' Send search string 'i' to browser n times
    Dim i As Integer
    For i = 1 To 100
        ' Browser search 
        WebBrowser1.Document.GetElementById("q").SetAttribute("value", i)
        WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click")
        ' Pause n seconds before next loop
        For x As Integer = 0 To 5 * 100 ' Pause for 5 seconds
            Threading.Thread.Sleep(10)
            Application.DoEvents()
        Next
    Next
End Sub
 
     
    