C# IE实例,文档太快完成执行
我在我的程序外创建了一个IE实例,程序会正确地找到并附加到该实例。我设置了事件处理程序,并告诉程序进入登录屏幕。DocumentCompleted句柄应该在网页完全加载时启动,但我的句柄似乎在新页面出现之前启动。。手柄只触发一次(意味着只有一帧?) 如果我将其修改为直接从登录页面开始工作,则此代码执行良好。。我做错什么了吗?感谢您的帮助:)C# IE实例,文档太快完成执行,c#,.net,browser,C#,.net,Browser,我在我的程序外创建了一个IE实例,程序会正确地找到并附加到该实例。我设置了事件处理程序,并告诉程序进入登录屏幕。DocumentCompleted句柄应该在网页完全加载时启动,但我的句柄似乎在新页面出现之前启动。。手柄只触发一次(意味着只有一帧?) 如果我将其修改为直接从登录页面开始工作,则此代码执行良好。。我做错什么了吗?感谢您的帮助:) Process.Start(@"IESpecial.exe"); SHDocVw.ShellWindows allBrow
Process.Start(@"IESpecial.exe");
SHDocVw.ShellWindows allBrowsers = new SHDocVw.ShellWindows();
while (true)
{
foreach (SHDocVw.WebBrowser ie in allBrowsers)
{
if (ie.LocationURL == "http://website/home.asp")
{
loggingIn = true;
webBrowser = ie;
webBrowser.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(webBrowser1_DocumentCompleted);
webBrowser.Navigate("http://website/logon.asp");
return;
}
}
Thread.Sleep(10);
}
}
private void webBrowser1_DocumentCompleted(object pDisp, ref object URL)
{
//we are attempting to log in
if (loggingIn)
{
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)webBrowser.Document;
mshtml.HTMLWindow2 window = (mshtml.HTMLWindow2)doc.IHTMLDocument2_parentWindow;
doc.getElementById("Username").setAttribute("value", "MLAPAGLIA");
doc.getElementById("Password").setAttribute("value", "PASSWORD");
window.execScript("SubmitAction()", "javascript");
loggingIn = false;
return;
}