本文介绍了等待webBrowser完成页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我有问题.
我使用webbrowser类登录到某个地方.
登录该站点后,我想访问一个链接.
问题是当我登录到该位置时,它不会访问该链接.如果我在登录后和访问链接之前显示一个消息框,则该消息框有效.
代码:
Hi !
I have a problem.
I use the webbrowser class to login to a place.
After I have logged into the site, I want to visit a link.
The problem is when I have logged into the place, it won´t visit the link. If I show an messagebox after logged in and before I visit the link, it works.
The Code:
//For login:
webBrowser3.Document.GetElementsByTagName("input")[1].InnerText = "password";
webBrowser3.Document.GetElementsByTagName("input")[0].InnerText = "username";
webBrowser3.Document.GetElementById("selection").Focus();
SendKeys.Send("{DOWN}");
SendKeys.Send("{TAB}");
SendKeys.Send("{Enter}");
//After this I being logged into the site
//After login
while (webBrowser3.ReadyState != WebBrowserReadyState.Interactive) Application.DoEvents();
{
Application.DoEvents();
}
webBrowser3.Document.Links[15].InvokeMember("click");
//Clicking the link.
//如果我在最后一个链接之前放置了一个消息框,则可以访问该链接,否则我将无法登录,就像webbrowser尚未完成加载页面一样.
关于Joakim
//If I put in a messagebox before the last link, I can visit the link, otherwise I dont get logged in, its like the webbrowser hasn´t finished loading the page.
Regards Joakim
推荐答案
protected void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (login_initiated == true)
{
webBrowser3.Document.Links[15].InvokeMember("click");
}
}
这篇关于等待webBrowser完成页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!