我试图点击我的网页浏览器中的按钮。
我在表单中创建了一个按钮来单击该按钮,但它给了我错误 在这一行
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