vb.net单击Web浏览器上的按钮时,对象引用未设置为对象错误的实例

时间:2015-05-11 19:48:02

标签: html vb.net button webbrowser-control

我试图点击我的网页浏览器中的按钮。

我在表单中创建了一个按钮来单击该按钮,但它给了我错误 在这一行

    Dim elements As HtmlElementCollection = custombrowser.Document.All
可能是因为该网站阻止我点击该按钮? 这是我的自定义浏览器类:

Public Class custombrowser


Inherits WebBrowser
Public Sub New()
    Me.ScriptErrorsSuppressed = True
End Sub
Private Sub docomplited() Handles Me.DocumentCompleted
    Dim TP As TabPage = Me.Tag



    My.Settings.ddd = TP.Text
    If Me.DocumentTitle.Length > 15 Then
        TP.Text = Me.DocumentTitle.Substring(0, 14) & ""
    Else
        TP.Text = Me.DocumentTitle


    End If
    My.Settings.ddd = TP.Text


End Sub

Private Sub custombrowser_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged

End Sub


Private Sub custombrowser_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles Me.Navigated
    Form1.Label1.Text = Me.Url.ToString
    End Sub
End Class

按钮代码:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


    If custombrowser.document IsNot Nothing Then
        Dim elements As HtmlElementCollection = custombrowser.Document.All



        For Each webpageelement As HtmlElement In elements
            custombrowser.Document.All("click").InvokeMember("click")
            If webpageelement.GetAttribute("class") = "click" Then

                webpageelement.InvokeMember("click")
            End If


        Next
    End If
End Sub

0 个答案:

没有答案