I am opening a website in a web browser control in vb.net 2008 . I want to programatically fill a form which is on the 3rd page of the website . But my code is unable to fill it . Can u plz guide me . I am using the following code

Public Class Form1
    Dim timercount As Integer = 1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("bla bla bla")

    End Sub





    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
        Dim txti As HtmlElement = WebBrowser1.Document.GetElementById("txtId")
        Dim txtp As HtmlElement = WebBrowser1.Document.GetElementById("txtPsw")
        Dim txti1 As HtmlElement = WebBrowser1.Document.GetElementById("txtId1")
        Dim txtd As HtmlElement = WebBrowser1.Document.GetElementById("txtDate")
        Dim txtr As HtmlElement = WebBrowser1.Document.GetElementById("txtRegion")
        Dim txte As HtmlElement = WebBrowser1.Document.GetElementById("txtEmail")
        Dim txtt As HtmlElement = WebBrowser1.Document.GetElementById("txtTitle")
        Dim txtu As HtmlElement = WebBrowser1.Document.GetElementById("txtUrl")
        Dim txtp1 As HtmlElement = WebBrowser1.Document.GetElementById("txtPin1")
        Dim txtp2 As HtmlElement = WebBrowser1.Document.GetElementById("txtPin2")
        Dim txtp3 As HtmlElement = WebBrowser1.Document.GetElementById("txtPin3")
        Dim txtp4 As HtmlElement = WebBrowser1.Document.GetElementById("txtPin4")
        Dim txtp5 As HtmlElement = WebBrowser1.Document.GetElementById("txtPin5")
        Dim txtpd As HtmlElement = WebBrowser1.Document.GetElementById("txtData")

        txti.SetAttribute("value", "E712050-15")
        txtp.SetAttribute("value", "HH29")



        txti1.SetAttribute("value", "E712050-15")
        txtd.SetAttribute("value", "")
        txtr.SetAttribute("value", "PAKISTAN")
        txte.SetAttribute("value", "excitedreams@yahoo.com")
        txtt.SetAttribute("value", "Best Classified Business.")
        txtu.SetAttribute("value", "// www.craigslist.org /")
        txtp1.SetAttribute("value", "W")
        txtp2.SetAttribute("value", "X")
        txtp3.SetAttribute("value", "M")
        txtp4.SetAttribute("value", "A")
        txtp5.SetAttribute("value", "F")
  End sub
  End class

i was working on a little project to log in a site using webbrowser (because i was bored)

Dim allWebPageElement As HtmlElementCollection = Me.WebBrowser1.Document.GetElementsByTagName("Input")

                For Each curElement As HtmlElement In allWebPageElement
                    Dim controlName As String = curElement.GetAttribute("id").ToString

                    If controlName = "emailAddress-small" Then
                        curElement.SetAttribute("Value", Me.IDTextBox.Text.ToString)
                    End If
                Next

Well, if the form is in "Input" leave it like that or else change it, Controlname is looking for elemts that has "id" if the controlname finds an element with "emailAddress-small" it will fill it with IDTextBox.text, so just edit the code a little and it should work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.