Html 单击webbrowser上的按钮时,vb.net对象引用未设置为对象错误的实例

Html 单击webbrowser上的按钮时,vb.net对象引用未设置为对象错误的实例,html,vb.net,button,webbrowser-control,Html,Vb.net,Button,Webbrowser Control,我正试图点击我的网络浏览器中的一个按钮 我在表单中创建了一个按钮来单击该按钮,但它给了我一个错误 在这条线上 Dim elements As HtmlElementCollection = custombrowser.Document.All 可能是网站阻止我点击那个按钮吗?? 这是我的自定义浏览器类: Public Class custombrowser Inherits WebBrowser Public Sub New() Me.ScriptErrorsSuppres

我正试图点击我的网络浏览器中的一个按钮

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

    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

按钮代码在哪里?下面是添加您告诉我的操作后的代码:如果custombrowser.document不是空的,则将每个webpageelement的元素设置为HtmlElementCollection=custombrowser.document.All,作为元素bba.document.All中的HtmleElement(单击”).InvokeMember(“单击”)如果webpageelement.GetAttribute(“类”)=“单击”,那么webpageelement.InvokeMember(“单击”)结束如果下一个结束如果您仍然有相同的错误?您在哪里(确切点)得到错误?现在新的错误出现在以下代码上:(如果custombrowser.document不是Nothing,则)这是错误:未设置对象变量或With block变量。custombrowser是类的名称。例如,对象的名称应为
cutombrowser1
。是否确定它的名称为
customborwser