表格 1 代码:
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://www.----------.org/login.php?")
WaitForPageLoad()
WebBrowser1.Document.GetElementById("username").SetAttribute("value", TextBox1.Text)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
WebBrowser1.Document.GetElementById("login").InvokeMember("Click")
End Sub
模块代码:
Private Property pageready As Boolean = False
区域“页面加载功能”
Private Sub WaitForPageLoad()
AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
pageready = True
RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
结束区域
所以我在互联网上搜索一个可以允许 webbrowser1 在继续下一个代码之前完全加载的模块,我在如何等待 WebBrowser 在 VB.NET 中完全加载?,但我在可访问性方面遇到了一些问题,(在模块 WebBrowser1.* 和主窗体上)它说没有声明,并且由于其保护级别可能无法访问。我是编程新手,希望有人可以帮助我。