C#如何在继续加载网页之前等待网页完成

我正在尝试创建一个程序,通过我们的缺陷跟踪系统的Web界面一次克隆多个错误。如何等待页面完全加载后才能继续?

//This is pseudo code, but this should give you an idea of what I'm trying to do.  The

//actual code uses multi-threading and all that good stuff :).

foreach (string bug in bugs)

{

webBrowser.Navigate(new Uri(url));

webBrowser.Document.GetElementById("product").SetAttribute("value", product);

webBrowser.Document.GetElementById("version").SetAttribute("value", version);

webBrowser.Document.GetElementById("commit").InvokeMember("click");

//Need code to wait for page to load before continuing.

}

回答:

尝试DocumentCompleted事件

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");

}

以上是 C#如何在继续加载网页之前等待网页完成 的全部内容, 来源链接: utcz.com/qa/420558.html

回到顶部