VB.NET - Click Submit Button on Webbrowser page

前端 未结 8 696
时光说笑
时光说笑 2021-02-09 02:30

I have a html page open on my webbrowser object, I can enter username and password okay, but I\'m stuck and don\'t know how to submit the info. Here is the html code for the us

8条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 03:03

    This seems to work easily.

    
    Public Function LoginAsTech(ByVal UserID As String, ByVal Pass As String) As Boolean
            Dim MyDoc As New mshtml.HTMLDocument
            Dim DocElements As mshtml.IHTMLElementCollection = Nothing
            Dim LoginForm As mshtml.HTMLFormElement = Nothing
    
            ASPComplete = 0
            WB.Navigate(VitecLoginURI)
            BrowserLoop()
    
            MyDoc = WB.Document.DomDocument
            DocElements = MyDoc.getElementsByTagName("input")
            For Each i As mshtml.IHTMLElement In DocElements
    
                Select Case i.name
                    Case "seLogin$UserName"
                        i.value = UserID
                    Case "seLogin$Password"
                        i.value = Pass
                    Case Else
                        Exit Select
                End Select
    
                frmServiceCalls.txtOut.Text &= i.name & " : " & i.value & " : " & i.type & vbCrLf
            Next i
    
            'Old Method for Clicking submit
            'WB.Document.Forms("form1").InvokeMember("submit")
    
    
            'Better Method to click submit
            LoginForm = MyDoc.forms.item("form1")
            LoginForm.item("seLogin$LoginButton").click()
            ASPComplete = 0
            BrowserLoop()
    
    
    
            MyDoc= WB.Document.DomDocument
            DocElements = MyDoc.getElementsByTagName("input")
            For Each j As mshtml.IHTMLElement In DocElements
                frmServiceCalls.txtOut.Text &= j.name & " : " & j.value & " : " & j.type & vbCrLf
    
            Next j
    
            frmServiceCalls.txtOut.Text &= vbCrLf & vbCrLf & WB.Url.AbsoluteUri & vbCrLf
            Return 1
    End Function
    

提交回复
热议问题