Detect WebBrowser complete page loading
I think the DocumentCompleted
event will get fired for all child documents that are loaded as well (like JS and CSS, for example). You could look at the WebBrowserDocumentCompletedEventArgs
in DocumentCompleted
and check the Url property and compare that to the Url of the main page.
Checking if WebBrowser has loaded
To check if it's loaded wherever, do:
if(browser.ReadyState == WebBrowserReadyState.Complete) {
// It's done!
}
However, if you're waiting for it to load, handle the DocumentCompleted
event instead:
browser.DocumentCompleted += WhenItsDone;
C# how to wait for a webpage to finish loading before continuing
Try the DocumentCompleted
Event:
webBrowser.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser.Document.GetElementById("product").SetAttribute("value", product);
webBrowser.Document.GetElementById("version").SetAttribute("value", version);
webBrowser.Document.GetElementById("commit").InvokeMember("click");
}
How to wait until WebBrowser is completely loaded in VB.NET?
Sounds like you want to catch the DocumentCompleted event of your webbrowser control.
MSDN has a couple of good articles about the webbrowser control - WebBrowser Class has lots of examples, and How to: Add Web Browser Capabilities to a Windows Forms Application
WebBrowser control - wait for page loading after submit form
You can try WebBrowser.DocumentCompleted Event
Occurs when the WebBrowser control finishes loading a document.
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("google.com");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show("Completed Now!");
}
How to make WebBrowser wait till it loads fully?
Add This to your code:
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
Fill in this function
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
//This line is so you only do the event once
if (e.Url != webBrowser1.Url)
return;
//do you actual code
}
Related Topics
Getting the Thread Id from a Thread
How to Inject a Dbcontext Instance into an Ihostedservice
How to Make Multi-Language App in Winforms
Why Should I Use Ihttpactionresult Instead of Httpresponsemessage
Avoiding First Chance Exception Messages When the Exception Is Safely Handled
Import and Export Excel - What Is the Best Library
Dynamically Adding Properties to an Expandoobject
Parsing Ftpwebrequest Listdirectorydetails Line
The Name 'Configurationmanager' Does Not Exist in the Current Context
Properly Draw Text Using Graphicspath
Purpose of Activator.Createinstance with Example
Export to Excel from a List with Epplus
How to Combine More Than Two Generic Lists in C# Zip