Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hello,

I have a project, where I need to automate IE (v8, but the same is valid for v11 also, thus I think it is general). The browser is started (or not) from the user, independent from my application. Thus I need to attach to it, and execute a script. That is not a problem with WatiN:
C#
IE ie = IE.AttachTo<IE>(Find.ByTitle("XYZ"),1);
ie.Eval("doit();");

So far so good. But my application won't exit. Actually the main() is finished, no statement left to execute, but the application is still not exiting. Except when the browser window is closed before I am closing my application. But I can't close it from my application and I can't make the user close it either - this is a constraint.
I had to actually kill the current process at the end of main() to stop it. But this is also not acceptable as the automation won't work when the application is restarted.

So, is there any way to "detach/release" attached instance with WatiN?
I am also open form alternatives as my ineraction with the browser is as simple as the sample above: finding a specific window and calling a script int that context.

Thank you,
Posted

1 solution

If no one can tell me how to solve this with WatiN, I will have to get rid of it, and do it in the old way:
C#
foreach (SHDocVw.IWebBrowser2/*or dynamic*/ ie in shellWindows)
{
if (ie.Document.Title.Contains("XYZl"))
     ie.Document.Script.execScript("doit();", "javascript");
}

At least it works, and does not hung my application.
Here is a quite good and short explanation for it: http://blog.likewise.org/2012/03/shdocvwshellwindows-and-iwebbrowser2-in/[^] (and some additions: http://stackoverflow.com/questions/6530083/cannot-add-c-windows-system32-shdocvw-dll-to-my-project/8541532#8541532[^])

Anyway, I am hoping for a solution in WatiN, but at least it is not that urgent anymore.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900