I have a unit test code that needs to open a page in IE and do something after the document is complete. The page contains redirects and at the end loads Silverlight (we are stuck with it for another year).
Here is the code:
using System;
using System.Threading;
using System.Windows.Forms;
using Common;
using NUnit.Framework;
using SHDocVw;
namespace Web
{
partial class ForEachWebServer
{
private class IEEvent
{
public object Url;
public void OnDocumentComplete(object pDisp, ref object URL)
{
Url = URL;
}
}
[Test, Category("non-ui"), Category("xap")]
[SkipTestExecutionForServicesBinding]
public void XAPDownload()
{
var ieEvent = new IEEvent();
var ie = new InternetExplorerClass();
ie.DocumentComplete += ieEvent.OnDocumentComplete;
ie.Visible = true;
ie.Navigate("ceridian.com");
while (ieEvent.Url == null)
{
Application.DoEvents();
Thread.Sleep(50);
}
Console.WriteLine($"Navigation complete: {ieEvent.Url}");
}
}
}
But ieEvent.Url remains null forever. Also if I try to access ie.Busy at some point while still waiting for the loop to end I get this:
System.Runtime.InteropServices.COMException: 'The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))'
What am I doing wrong?
EDIT 1
I have a fully functional project here - https://dev.azure.com/MarkKharitonov0271/_git/BrowserTest
DocumentComplete event arrives for ceridian. Closing the dialog ends the application.DocumentComplete event arrives for X. Closing the dialog ends the application.Now, all works fine for:
BrowserTest.exeBrowserTest.exe liveBrowserTest.exe googleBut, running BrowserTest.exe ceridian never opens the modal dialog. So, something must be wrong with the code, but what ???
User contributions licensed under CC BY-SA 3.0