Question How to click a button in a webbrowser which is created in a loop?

Mixx

New member
Joined
Apr 19, 2011
Messages
3
Location
Veenendaal, Netherlands
Programming Experience
Beginner
Hello,

In my application, i want to have 10 webbrowsers, which go to google like this.

VB.NET:
For i = 0 To 9
            Dim Browser As New WebBrowser
            Browser.Name = "Browser" & [i]
            Browser.Navigate("http://www.google.com")
            Browser.Visible = True
        Next

So now i will have 10 webbrowsers aimed for google, right? So how do i make a loop that clicks the search button 10 times?
I know i need to use member_invoke like this
VB.NET:
Browser.Document.GetElementById("search").InvokeMember("click")

But i have no clue how to code the loop. Any tips please?
 
Bump, anyone? :(

I tried figuring out a solution like this;
VB.NET:
For Each Ctr As Control In Me.Controls
            If TypeOf Ctr Is WebBrowser Then
                Console.WriteLine("found browser: " & Ctr.name)
                Ctr.document.GetElementById("connect-button").InvokeMember("click")

But i cant use webbrowser controls on a control object, naturally. All i need now is to get the webbrowsername into the code.
Or am i completely going the wrong way?
 
Why not just track each webbrowser, ie add them to a list when you create them. Then just InvokeMember on each item in the list.

Make sure you Dispose() of the WebBrowsers when you finish with them.
 
Back
Top