问题
As the title says, how can i know if the gecko browser completed loading a web page? I know there is document_completed event. But it will get triggered for every time a web page loads. Are there any other ways to check if the current webpage is completed loading.
回答1:
Do While WebBrowser.IsBusy = True
Application.DoEvents()
Loop
Works for me. After WebBrowser.Navigate
you have to wait for some time (I use 1 second) before IsBusy
becomes True
回答2:
My Solotion in vb.net and GeckoFX v45.0.34.0 you can use this tool convert to c# (http://converter.telerik.com/):
Private vWeb As GeckoWebBrowser = New GeckoWebBrowser
Private Property pageready As Boolean = False
Private Sub WaitForPageLoad()
AddHandler vWeb.DocumentCompleted, New EventHandler(Of GeckoDocumentCompletedEventArgs)(AddressOf PageWaiter)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As GeckoDocumentCompletedEventArgs)
If vWeb.IsBusy = False Then
pageready = True
RemoveHandler vWeb.DocumentCompleted, New EventHandler(Of GeckoDocumentCompletedEventArgs)(AddressOf PageWaiter)
End If
End Sub
Using:
vWeb.Navigate("https://www.google.com")
WaitForPageLoad()
//Do your Work
Hope this solution to resolve.
来源:https://stackoverflow.com/questions/33116446/how-to-know-if-gecko-browser-completed-loading-a-webpage