请教有一段模拟IE 点击程序
.......
this.webBrowser1.Navigate(manager_html, false); //打开登录界面
loginali(); //登录
......
在调用的时候经常出现webbrowser没有加载完后就执行loginali()的程序造成程序出错.如果页面加载完了,就又能正常使用?请教各位有什么办法可以解决?
有没有webBrowser的强制运行的?然后在运行下一句
登录程序如下
private void loginali()
{
HtmlElement ClickBtn = null; HtmlDocument doc = this.webBrowser1.Document;
for (int i = 0; i < doc.All.Count; i++)
{
if (doc.All[i].TagName.ToUpper().Equals("INPUT"))
{
switch (doc.All[i].Name)
{
case "LoginId":
doc.All[i].InnerText = this.username.Text.Trim();
break;
case "Password":
doc.All[i].InnerText = this.use_pass.Text.Trim();
break;
case "button2":
ClickBtn = doc.All[i]; //提交按钮
break;
}
}
}
ClickBtn.InvokeMember("Click");
}
.......
this.webBrowser1.Navigate(manager_html, false); //打开登录界面
loginali(); //登录
......
在调用的时候经常出现webbrowser没有加载完后就执行loginali()的程序造成程序出错.如果页面加载完了,就又能正常使用?请教各位有什么办法可以解决?
有没有webBrowser的强制运行的?然后在运行下一句
登录程序如下
private void loginali()
{
HtmlElement ClickBtn = null; HtmlDocument doc = this.webBrowser1.Document;
for (int i = 0; i < doc.All.Count; i++)
{
if (doc.All[i].TagName.ToUpper().Equals("INPUT"))
{
switch (doc.All[i].Name)
{
case "LoginId":
doc.All[i].InnerText = this.username.Text.Trim();
break;
case "Password":
doc.All[i].InnerText = this.use_pass.Text.Trim();
break;
case "button2":
ClickBtn = doc.All[i]; //提交按钮
break;
}
}
}
ClickBtn.InvokeMember("Click");
}
while(this.webBrowser1.ReadyState!=Complate)
{
Application.DoEvents();
}
你在webBrowser的DocumentCompleted事件里写loginali的内容就没事了
while (this.webBrowser1.ReadyState !=[b] WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
楼上的
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
这个里面我也加了标志位在调试的时候总感觉怪怪的? 但没有看出什么问题! 多谢