WebBrowser Forms

dennisvb

Member
Joined
Nov 19, 2009
Messages
10
Programming Experience
10+
I am trying to rewrite an ap I wrote in Vb6 to VBNet 2008

PArt of requires signing in to a website automatically.

In VB6 it was simple:

Web1 is my webbrowser control


Set doc1 = WEB1.Document
Set f1 = doc1.Forms
Set Form = f1(0)
Set els = Form.elements
els(13).Value =User
els(14).Value = Password
els(15).Click


I've gotten this far in VB.Net

Public doc1 As HtmlDocumen
Public frm As HtmlElementColection

doc1 = Form1.WEB1.Document
frm = doc1.Forms

Can some tell me what data type I need for the form elements? I have tried HTMLELEMNT but that doesn't let me change the value or click.
 
Here's an exampled worked out for this website.
VB.NET:
        WebBrowser1.Document.GetElementById("navbar_username").SetAttribute("value", txtUsername)
        WebBrowser1.Document.GetElementById("navbar_password").SetAttribute("value", txtPassword)
        Dim intInput As Integer
        For intInput = 0 To WebBrowser1.Document.GetElementsByTagName("Input").Count
            If WebBrowser1.Document.GetElementsByTagName("Input").Item(intInput).GetAttribute("Value") = "Log in" Then
                WebBrowser1.Document.GetElementsByTagName("Input").Item(intInput).InvokeMember("Click")
                Exit Sub
            End If
        Next
 
Dim intInput As Integer
For intInput = 0 To WebBrowser1.Document.GetElementsByTagName("Input").Count
If WebBrowser1.Document.GetElementsByTagName("Input").Item(intInput).GetAttribute("Value") = "Log in" Then
WebBrowser1.Document.GetElementsByTagName("Input").Item(intInput).InvokeMember("Click")
Exit Sub
End If
Next
You only need to call GetElementsByTagName once here and loop the results.
VB.NET:
Dim inputs As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For i As Integer = 0 To (input.Length - 1)
    inputs(i).blah()
or better yet;
VB.NET:
For Each input As HtmlElement In WebBrowser1.Document.GetElementsByTagName("Input")
    input.blah()
 
Back
Top