-
Mar 13th, 2010, 04:03 PM
#1
Thread Starter
Lively Member
[RESOLVED] How to test if URL is completely loaded in WebBrowser
I need to make a condition such that my program waits until the webpage is completely loaded before executing my provided commands.
If anyone could help that would be great.
Thank you for reading
-
Mar 13th, 2010, 04:04 PM
#2
Fanatic Member
Re: How to test if URL is completely loaded in WebBrowser
Code:
if webbrowser1.isbusy = true then
'do nothing
else
'do what you want
end if
-
Mar 13th, 2010, 05:08 PM
#3
Re: How to test if URL is completely loaded in WebBrowser
You can also use the default, DocumentCompleted event for the WebBrowser control. Just create the event by double clicking on the component and then execute all of your code in it.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 13th, 2010, 05:09 PM
#4
Fanatic Member
Re: How to test if URL is completely loaded in WebBrowser
ah yes, forgot about that one.
You could use either or.
-
Mar 13th, 2010, 05:10 PM
#5
Re: How to test if URL is completely loaded in WebBrowser
Originally Posted by TCarter
Code:
if webbrowser1.isbusy = true then
'do nothing
else
'do what you want
end if
Also, I haven't tested it, but I don't think that will work. You'd probably need a loop instead of a conditional statement. With this code, it checks if the WebBrowser is busy, once, and then moves on. If it is busy, then it will move on and not give the WebBrowser time to complete.
Although not usually suggested, the OP can also use a While statment to check if it's busu and use Application.DoEvents while it's busy.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Mar 13th, 2010, 06:04 PM
#6
Thread Starter
Lively Member
Re: How to test if URL is completely loaded in WebBrowser
Yes, I thought the same thing, the If statement will only check to see if it is loaded once. I need it to tell me when it is done loading.
I'm not sure how to write the while loop to continuously check until it is loaded.
-
Mar 13th, 2010, 06:11 PM
#7
Re: How to test if URL is completely loaded in WebBrowser
If you want to do something as soon as page load is complete, use the DocumentCompleted event. In case you want to know at some random point whether the current page in webbrowser is fully loaded or not then use the ReadyState property.
vb.net Code:
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then 'whatever End If
-
Mar 13th, 2010, 06:22 PM
#8
Thread Starter
Lively Member
Re: How to test if URL is completely loaded in WebBrowser
I'm still unsure of how to use DocumentCompleted.
Let's say I navigate to "google.com"
I want to wait until Google has been finished loading until I perform anything else.
-
Mar 13th, 2010, 06:35 PM
#9
Re: How to test if URL is completely loaded in WebBrowser
e.g.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click WebBrowser1.Navigate("http://www.google.com") End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted MessageBox.Show("Document loading completed!") End Sub
-
Mar 13th, 2010, 09:09 PM
#10
Fanatic Member
Re: [RESOLVED] How to test if URL is completely loaded in WebBrowser
a loop wouldnt be too far off depending on what he is doing...and if he didnt want to limit a webbrowser control to any 1 thing.
Regardless, it is resolved.
-
Mar 13th, 2010, 09:13 PM
#11
Thread Starter
Lively Member
Re: [RESOLVED] How to test if URL is completely loaded in WebBrowser
It's solved, and the DocumentCompleted option works perfect and is very efficient.
-
Aug 30th, 2015, 10:54 AM
#12
New Member
Re: How to test if URL is completely loaded in WebBrowser
Hold on...
As per the following answer:
http://stackoverflow.com/a/32298026/2396732
Since IE11 informs of DocumentCompleted multiple times, so it's better to check what URL is completed:
Code:
' Page, sub-frame or resource was totally loaded.
Private Sub webBrowser1_DocumentCompleted(sender As Object, _
e As WebBrowserDocumentCompletedEventArgs) _
Handles webBrowser1.DocumentCompleted
' Check if finally the full page was loaded (inc. sub-frames, javascripts, etc)
If e.Url.ToString = webBrowser1.Url.ToString Then
' Only now you are sure!
fullyLoaded = True
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|